3 * fast mathematics routines.
7 * A Fast, Compact Approximation of the Exponential Function
9 * IDSIA, Lugano, Switzerland
10 * http://www.inf.ethz.ch/~schraudo/pubs/exp.pdf
12 * Fast log() Function, by Laurent de Soras:
13 * http://www.flipcode.com/cgi-bin/msg.cgi?showThread=Tip-Fastlogfunction&forum=totd&id=-1
22 #define _SG_FMATH_HXX 1
25 # error This library requires C++
29 #define _USE_MATH_DEFINES
34 double fast_exp(double val);
36 void fast_BSL(float &x, register unsigned long shiftAmount);
37 void fast_BSR(float &x, register unsigned long shiftAmount);
39 inline float fast_log2 (float val)
41 int * const exp_ptr = reinterpret_cast <int *> (&val);
43 const int log_2 = ((x >> 23) & 255) - 128;
48 val = ((-1.0f/3) * val + 2) * val - 2.0f/3; // (1)
54 * This function is about 3 times faster than the system log() function
55 * and has an error of about 0.01%
57 inline float fast_log (const float &val)
59 return (fast_log2 (val) * 0.69314718f);
62 inline float fast_log10 (const float &val)
64 return (fast_log2(val) / 3.321928095f);
68 #endif // !_SG_FMATH_HXX