1 /**************************************************************************
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)
9 **************************************************************************/
13 * This file allows to compute the minimax polynomial coefficients we use
16 * How to use this source:
18 * - Download and build the NTL library from
19 * http://shoup.net/ntl/download.html , or install libntl-dev package if on
22 * - Download boost source code matching to your distro.
24 * - Goto libs/math/minimax and replace f.cpp with this file.
28 * g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a
34 * - For example, to compute log2 5th order polynomial between [1, 2] do:
42 * and take the coefficients from the P = { ... } array.
44 * - To compute exp2 5th order polynomial between [0, 1] do:
53 * http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html
57 #include <boost/math/bindings/rr.hpp>
58 #include <boost/math/tools/polynomial.hpp>
63 boost::math::ntl::RR
f(const boost::math::ntl::RR
& x
, int variant
)
65 static const boost::math::ntl::RR tiny
= boost::math::tools::min_value
<boost::math::ntl::RR
>() * 64;
71 return log(x
)/log(2.0)/(x
- 1.0);
75 return exp(x
*log(2.0));
83 const boost::math::tools::polynomial
<boost::math::ntl::RR
>& n
,
84 const boost::math::tools::polynomial
<boost::math::ntl::RR
>& d
,
85 const boost::math::ntl::RR
& x_offset
,
86 const boost::math::ntl::RR
& y_offset
,