Path: blob/21.2-virgl/src/gallium/auxiliary/gallivm/f.cpp
4565 views
/**************************************************************************1*2* (C) Copyright VMware, Inc 2010.3* (C) Copyright John Maddock 2006.4* Use, modification and distribution are subject to the5* Boost Software License, Version 1.0. (See accompanying file6* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)7*8**************************************************************************/91011/*12* This file allows to compute the minimax polynomial coefficients we use13* for fast exp2/log2.14*15* How to use this source:16*17* - Download and build the NTL library from18* http://shoup.net/ntl/download.html , or install libntl-dev package if on19* Debian.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 as26*27* g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a28*29* - Run as30*31* ./minimax32*33* - For example, to compute exp2 5th order polynomial between [0, 1] do:34*35* variant 036* range 0 137* order 5 038* step 20039* info40*41* and take the coefficients from the P = { ... } array.42*43* - To compute log2 4th order polynomial between [0, 1/9] do:44*45* variant 146* range 0 0.11111111247* order 4 048* step 20049* info50*51* - For more info see52* http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html53*/5455#define L2256#include <boost/math/bindings/rr.hpp>57#include <boost/math/tools/polynomial.hpp>5859#include <cmath>6061boost::math::ntl::RR exp2(const boost::math::ntl::RR& x)62{63return exp(x*log(2.0));64}6566boost::math::ntl::RR log2(const boost::math::ntl::RR& x)67{68return log(x)/log(2.0);69}7071boost::math::ntl::RR f(const boost::math::ntl::RR& x, int variant)72{73switch(variant)74{75case 0:76return exp2(x);7778case 1:79return log2((1.0 + sqrt(x))/(1.0 - sqrt(x)))/sqrt(x);80}8182return 0;83}848586void show_extra(87const boost::math::tools::polynomial<boost::math::ntl::RR>& n,88const boost::math::tools::polynomial<boost::math::ntl::RR>& d,89const boost::math::ntl::RR& x_offset,90const boost::math::ntl::RR& y_offset,91int variant)92{93switch(variant)94{95default:96// do nothing here...97;98}99}100101102103