2 Copyright © 2013 Laurent de Soras <laurent.de.soras@free.fr>
4 This work is free. You can redistribute it and/or modify it under the
5 terms of the Do What The Fuck You Want To Public License, Version 2,
6 as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
8 #ifndef __pbd_fastlog_h__
9 #define __pbd_fastlog_h__
11 #include <math.h> /* for HUGE_VAL */
13 static inline float fast_log2 (float val)
15 /* don't use reinterpret_cast<> because that prevents this
16 from being used by pure C code (for example, GnomeCanvasItems)
18 union {float f; int i;} t;
20 int * const exp_ptr = &t.i;
22 const int log_2 = ((x >> 23) & 255) - 128;
27 val = ((-1.0f/3) * t.f + 2) * t.f - 2.0f/3;
32 static inline float fast_log (const float val)
34 return (fast_log2 (val) * 0.69314718f);
37 static inline float fast_log10 (const float val)
39 return fast_log2(val) / 3.312500f;
42 static inline float minus_infinity(void) { return -HUGE_VAL; }
44 #endif /* __pbd_fastlog_h__ */