}
-double fast_log2 (double val)
-{
- int * const exp_ptr = reinterpret_cast <int *> (&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;
#include <math.h>
-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 <int *> (&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
#include <simgear/debug/logstream.hxx>
#include <simgear/props/condition.hxx>
-#include <simgear/math/fastmath.hxx>
#include "sound.hxx"
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; }