1 /* Copyright unknown. Code by Laurent de Soras <laurent@ohmforce.com>.
4 #ifndef __pbd_fastlog_h__
5 #define __pbd_fastlog_h__
7 #include <math.h> /* for HUGE_VAL */
9 static inline float fast_log2 (float val)
11 /* don't use reinterpret_cast<> because that prevents this
12 from being used by pure C code (for example, GnomeCanvasItems)
14 union {float f; int i;} t;
16 int * const exp_ptr = &t.i;
18 const int log_2 = ((x >> 23) & 255) - 128;
23 val = ((-1.0f/3) * t.f + 2) * t.f - 2.0f/3;
28 static inline float fast_log (const float val)
30 return (fast_log2 (val) * 0.69314718f);
33 static inline float fast_log10 (const float val)
35 return fast_log2(val) / 3.312500f;
38 static inline float minus_infinity() { return -HUGE_VAL; }
40 #endif /* __pbd_fastlog_h__ */