Fixed i18n system.
[ardour.git] / libs / pbd / pbd / fastlog.h
1 /* Copyright unknown. Code by Laurent de Soras <laurent@ohmforce.com>.
2  */
3
4 #ifndef __pbd_fastlog_h__
5 #define __pbd_fastlog_h__
6
7 #include <math.h> /* for HUGE_VAL */
8
9 static inline float fast_log2 (float val)
10 {
11         /* don't use reinterpret_cast<> because that prevents this
12            from being used by pure C code (for example, GnomeCanvasItems)
13         */
14         union {float f; int i;} t;
15         t.f = val;
16         int * const    exp_ptr =  &t.i;
17         int            x = *exp_ptr;
18         const int      log_2 = ((x >> 23) & 255) - 128;
19         x &= ~(255 << 23);
20         x += 127 << 23;
21         *exp_ptr = x;
22         
23         val = ((-1.0f/3) * t.f + 2) * t.f - 2.0f/3;
24         
25         return (val + log_2);
26 }
27
28 static inline float fast_log (const float val)
29 {
30         return (fast_log2 (val) * 0.69314718f);
31 }
32
33 static inline float fast_log10 (const float val)
34 {
35         return fast_log2(val) / 3.312500f;
36 }
37
38 static inline float minus_infinity() { return -HUGE_VAL; }
39
40 #endif /* __pbd_fastlog_h__ */