util: Move gallium's PIPE_FORMAT utils to /util/format/
[mesa.git] / src / gallium / auxiliary / gallivm / f.cpp
index 5eb09c01ab32200a3b64d7dcd71277c9367faf99..4b33e49b477725b7b353d650afd3d81299c9aa88 100644 (file)
@@ -15,8 +15,9 @@
  *
  * How to use this source:
  *
- * - Download and abuild the NTL library from
- *   http://shoup.net/ntl/download.html
+ * - Download and build the NTL library from
+ *   http://shoup.net/ntl/download.html , or install libntl-dev package if on
+ *   Debian.
  *
  * - Download boost source code matching to your distro. 
  *
@@ -24,7 +25,7 @@
  *
  * - Build as
  *
- *   g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a -lboost_math_tr1
+ *   g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a
  *
  * - Run as 
  *
  *
  * - For example, to compute exp2 5th order polynomial between [0, 1] do:
  *
- *    variant 1
+ *    variant 0
  *    range 0 1
  *    order 5 0
- *    steps 200
+ *    step 200
+ *    info
+ *
+ *  and take the coefficients from the P = { ... } array.
+ *
+ * - To compute log2 4th order polynomial between [0, 1/9] do:
+ *
+ *    variant 1
+ *    range 0 0.111111112
+ *    order 4 0
+ *    step 200
  *    info
  *
  * - For more info see
- * http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html
+ * http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html
  */
 
 #define L22
 
 #include <cmath>
 
+boost::math::ntl::RR exp2(const boost::math::ntl::RR& x)
+{
+      return exp(x*log(2.0));
+}
+
+boost::math::ntl::RR log2(const boost::math::ntl::RR& x)
+{
+      return log(x)/log(2.0);
+}
 
 boost::math::ntl::RR f(const boost::math::ntl::RR& x, int variant)
 {
-   static const boost::math::ntl::RR tiny = boost::math::tools::min_value<boost::math::ntl::RR>() * 64;
-   
    switch(variant)
    {
    case 0:
-      // log2(x)/(x - 1)
-      return log(x)/log(2.0)/(x - 1.0);
+      return exp2(x);
 
    case 1:
-      // exp2(x)
-      return exp(x*log(2.0));
+      return log2((1.0 + sqrt(x))/(1.0 - sqrt(x)))/sqrt(x);
    }
 
    return 0;