From e40fc849149dd97c248866a4a1d026dda5e57b62 Mon Sep 17 00:00:00 2001 From: Robert Jonsson Date: Mon, 7 Mar 2011 19:01:11 +0000 Subject: clean3 --- attic/muse2-oom/muse2/awl/fastlog.h | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 attic/muse2-oom/muse2/awl/fastlog.h (limited to 'attic/muse2-oom/muse2/awl/fastlog.h') diff --git a/attic/muse2-oom/muse2/awl/fastlog.h b/attic/muse2-oom/muse2/awl/fastlog.h new file mode 100644 index 00000000..90a85342 --- /dev/null +++ b/attic/muse2-oom/muse2/awl/fastlog.h @@ -0,0 +1,39 @@ +/* Copyright unknown. Code by Laurent de Soras . + */ + +#ifndef __FASTLOG_H__ +#define __FASTLOG_H__ + +#include /* 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 + -- cgit v1.2.3