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
23 #include <fastmath.hxx>
26 * This function is on avarage 9 times faster than the system exp() function
27 * and has an error of about 1.5%
32 #if BYTE_ORDER == BIG_ENDIAN
40 double fast_exp(double val) {
41 const double a = 1048576/M_LN2;
42 const double b_c = 1072632447; /* 1072693248 - 60801 */
44 _eco.n.i = a*val + b_c;
50 double fast_log2 (double val)
52 int * const exp_ptr = reinterpret_cast <int *> (&val);
54 const int log_2 = ((x >> 23) & 255) - 128;
59 val = ((-1.0f/3) * val + 2) * val - 2.0f/3; // (1)
65 * This function is about 3 times faster than the system log() function
66 * and has an error of about 0.01%
68 double fast_log (double val)
70 return (fast_log2 (val) * 0.69314718f);
73 double fast_log10 (double val)
75 return (fast_log (val) / fast_log (10));
80 * While we're on the subject, someone might have use for these as well?
81 * Float Shift Left and Float Shift Right. Do what you want with this.
83 void fast_BSL(double &x, register unsigned long shiftAmount) {
85 *(unsigned long*)&x+=shiftAmount<<23;
89 void fast_BSR(double &x, register unsigned long shiftAmount) {
91 *(unsigned long*)&x-=shiftAmount<<23;