From: ehofman Date: Sat, 28 Jun 2003 12:58:59 +0000 (+0000) Subject: Fix some problems X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dcdf8a4d5c6b526dc58445b647d37c1fb53f2748;p=simgear.git Fix some problems --- diff --git a/simgear/math/fastmath.cxx b/simgear/math/fastmath.cxx index ce8e253b..c95ccbcc 100644 --- a/simgear/math/fastmath.cxx +++ b/simgear/math/fastmath.cxx @@ -47,46 +47,17 @@ double fast_exp(double val) { } -double fast_log2 (double val) -{ - int * const exp_ptr = reinterpret_cast (&val); - 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) * val + 2) * val - 2.0f/3; // (1) - - return (val + log_2); -} - -/** - * This function is about 3 times faster than the system log() function - * and has an error of about 0.01% - */ -double fast_log (double val) -{ - return (fast_log2 (val) * 0.69314718f); -} - -double fast_log10 (double val) -{ - return (fast_log (val) / fast_log (10)); -} - - /** * While we're on the subject, someone might have use for these as well? * Float Shift Left and Float Shift Right. Do what you want with this. */ -void fast_BSL(double &x, register unsigned long shiftAmount) { +void fast_BSL(float &x, register unsigned long shiftAmount) { *(unsigned long*)&x+=shiftAmount<<23; } -void fast_BSR(double &x, register unsigned long shiftAmount) { +void fast_BSR(float &x, register unsigned long shiftAmount) { *(unsigned long*)&x-=shiftAmount<<23; diff --git a/simgear/math/fastmath.hxx b/simgear/math/fastmath.hxx index b2b5595a..7ce8f461 100644 --- a/simgear/math/fastmath.hxx +++ b/simgear/math/fastmath.hxx @@ -28,12 +28,40 @@ #include -double fast_exp(double y); -double fast_log(double val); -double fast_log2 (double val); -double fast_log10(double val); -void fast_BSL(double &x, register unsigned long shiftAmount); -void fast_BSR(double &x, register unsigned long shiftAmount); + +double fast_exp(double val); + +void fast_BSL(float &x, register unsigned long shiftAmount); +void fast_BSR(float &x, register unsigned long shiftAmount); + +inline float fast_log2 (float val) +{ + int * const exp_ptr = reinterpret_cast (&val); + 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) * val + 2) * val - 2.0f/3; // (1) + + return (val + log_2); +} + +/** + * This function is about 3 times faster than the system log() function + * and has an error of about 0.01% + */ +inline float fast_log (const float &val) +{ + return (fast_log2 (val) * 0.69314718f); +} + +inline float fast_log10 (const float &val) +{ + return (fast_log2(val) / 3.321928095f); +} + #endif // !_SG_FMATH_HXX diff --git a/simgear/sound/sound.cxx b/simgear/sound/sound.cxx index 8ceaf182..280f72e0 100644 --- a/simgear/sound/sound.cxx +++ b/simgear/sound/sound.cxx @@ -32,7 +32,6 @@ #include #include -#include #include "sound.hxx" @@ -42,8 +41,8 @@ static double _snd_inv(double v) { return (v == 0) ? 1e99 : 1/v; } static double _snd_abs(double v) { return (v >= 0) ? v : -v; } static double _snd_sqrt(double v) { return (v < 0) ? sqrt(-v) : sqrt(v); } -static double _snd_log10(double v) { return (v < 1) ? 0 : fast_log10(v); } -static double _snd_log(double v) { return (v < 1) ? 0 : fast_log(v); } +static double _snd_log10(double v) { return (v < 1) ? 0 : log10(v); } +static double _snd_log(double v) { return (v < 1) ? 0 : log(v); } // static double _snd_sqr(double v) { return v*v; } // static double _snd_pow3(double v) { return v*v*v; }