summaryrefslogtreecommitdiff
path: root/muse2/muse/fastlog.h
diff options
context:
space:
mode:
authorRobert Jonsson <spamatica@gmail.com>2010-10-13 19:34:22 +0000
committerRobert Jonsson <spamatica@gmail.com>2010-10-13 19:34:22 +0000
commit8a2c2824a59d7644e13bc52c9a0ecbd641f21f95 (patch)
tree064ad3f2bf8daab0ad27b128abd86a9bbdb1e496 /muse2/muse/fastlog.h
parenta27706d9629e8b592cca4659f865b70adef24e6d (diff)
new branch muse2, first checkin
Diffstat (limited to 'muse2/muse/fastlog.h')
-rw-r--r--muse2/muse/fastlog.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/muse2/muse/fastlog.h b/muse2/muse/fastlog.h
new file mode 100644
index 00000000..23710a8b
--- /dev/null
+++ b/muse2/muse/fastlog.h
@@ -0,0 +1,38 @@
+/* Copyright unknown. Code by Laurent de Soras <laurent@ohmforce.com>.
+ */
+
+#ifndef __pbd_fastlog_h__
+#define __pbd_fastlog_h__
+
+#include <math.h> /* for HUGE_VAL */
+
+static inline float fast_log2 (float val)
+ {
+ /* don't use reinterpret_cast<> because that prevents this
+ from being used by pure C code (for example, GnomeCanvasItems)
+ */
+ union {float f; int i;} t;
+ t.f = val;
+ int* const exp_ptr = &t.i;
+ int x = *exp_ptr;
+ const int log_2 = ((x >> 23) & 255) - 128;
+ x &= ~(255 << 23);
+ x += 127 << 23;
+ *exp_ptr = x;
+ val = ((-1.0f/3) * t.f + 2) * t.f - 2.0f/3;
+ return (val + log_2);
+ }
+
+static inline float fast_log (const float val)
+ {
+ return (fast_log2 (val) * 0.69314718f);
+ }
+
+static inline float fast_log10 (const float val)
+ {
+ return fast_log2(val) / 3.312500f;
+ }
+
+static inline float minus_infinity() { return -HUGE_VAL; }
+
+#endif /* __pbd_fastlog_h__ */