summaryrefslogtreecommitdiff
path: root/muse2/awl/fastlog.h
diff options
context:
space:
mode:
authorTim E. Real <termtech@rogers.com>2010-11-28 21:14:50 +0000
committerTim E. Real <termtech@rogers.com>2010-11-28 21:14:50 +0000
commit8dc8689a009a3702bf4135e628f9d63df8b2ea36 (patch)
treefea6d4781b06fabfb24255751df95de750099830 /muse2/awl/fastlog.h
parentb121a3b91f0e288934c4d78161ff1d20f96ff861 (diff)
Added AWL files
Diffstat (limited to 'muse2/awl/fastlog.h')
-rw-r--r--muse2/awl/fastlog.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/muse2/awl/fastlog.h b/muse2/awl/fastlog.h
new file mode 100644
index 00000000..90a85342
--- /dev/null
+++ b/muse2/awl/fastlog.h
@@ -0,0 +1,39 @@
+/* Copyright unknown. Code by Laurent de Soras <laurent@ohmforce.com>.
+ */
+
+#ifndef __FASTLOG_H__
+#define __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
+