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 int * const exp_ptr = (int *)(&val);
16 const int log_2 = ((x >> 23) & 255) - 128;
21 val = ((-1.0f/3) * val + 2) * val - 2.0f/3; // (1)
26 static inline float fast_log (const float val)
28 return (fast_log2 (val) * 0.69314718f);
31 static inline float fast_log10 (const float val)
33 return fast_log2(val) / 3.312500f;
36 static inline float minus_infinity() { return -HUGE_VAL; }
38 #endif /* __pbd_fastlog_h__ */