f.cpp revision 3464ebd5
1/************************************************************************** 2 * 3 * (C) Copyright VMware, Inc 2010. 4 * (C) Copyright John Maddock 2006. 5 * Use, modification and distribution are subject to the 6 * Boost Software License, Version 1.0. (See accompanying file 7 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 * 9 **************************************************************************/ 10 11 12/* 13 * This file allows to compute the minimax polynomial coefficients we use 14 * for fast exp2/log2. 15 * 16 * How to use this source: 17 * 18 * - Download and abuild the NTL library from 19 * http://shoup.net/ntl/download.html 20 * 21 * - Download boost source code matching to your distro. 22 * 23 * - Goto libs/math/minimax and replace f.cpp with this file. 24 * 25 * - Build as 26 * 27 * g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a -lboost_math_tr1 28 * 29 * - Run as 30 * 31 * ./minimax 32 * 33 * - For example, to compute exp2 5th order polynomial between [0, 1] do: 34 * 35 * variant 1 36 * range 0 1 37 * order 5 0 38 * steps 200 39 * info 40 * 41 * - For more info see 42 * http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html 43 */ 44 45#define L22 46#include <boost/math/bindings/rr.hpp> 47#include <boost/math/tools/polynomial.hpp> 48 49#include <cmath> 50 51 52boost::math::ntl::RR f(const boost::math::ntl::RR& x, int variant) 53{ 54 static const boost::math::ntl::RR tiny = boost::math::tools::min_value<boost::math::ntl::RR>() * 64; 55 56 switch(variant) 57 { 58 case 0: 59 // log2(x)/(x - 1) 60 return log(x)/log(2.0)/(x - 1.0); 61 62 case 1: 63 // exp2(x) 64 return exp(x*log(2.0)); 65 } 66 67 return 0; 68} 69 70 71void show_extra( 72 const boost::math::tools::polynomial<boost::math::ntl::RR>& n, 73 const boost::math::tools::polynomial<boost::math::ntl::RR>& d, 74 const boost::math::ntl::RR& x_offset, 75 const boost::math::ntl::RR& y_offset, 76 int variant) 77{ 78 switch(variant) 79 { 80 default: 81 // do nothing here... 82 ; 83 } 84} 85 86