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;
51 * While we're on the subject, someone might have use for these as well?
52 * Float Shift Left and Float Shift Right. Do what you want with this.
54 void fast_BSL(float &x, register unsigned long shiftAmount) {
56 *(unsigned long*)&x+=shiftAmount<<23;
60 void fast_BSR(float &x, register unsigned long shiftAmount) {
62 *(unsigned long*)&x-=shiftAmount<<23;