]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/fastmath.hxx
Ignore generated binaries.
[simgear.git] / simgear / math / fastmath.hxx
index 288d3444145a54f99c4ba860f533cc26dde5cd96..2408f51e91017db5d2689221d79fd3f7fe114f4f 100644 (file)
@@ -25,9 +25,6 @@
 # error This library requires C++
 #endif
 
-#ifdef _MSC_VER
-#define  _USE_MATH_DEFINES
-#endif
 #include <math.h>
 
 
@@ -54,16 +51,18 @@ 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);
+    union {
+        float f;
+        int i;
+    } v;
+    v.f = val;
+    const int log_2 = ((v.i >> 23) & 255) - 128;
+    v.i &= ~(255 << 23);
+    v.i += 127 << 23;
+
+    v.f = ((-1.0f/3) * v.f + 2) * v.f - 2.0f/3;   // (1)
+
+    return (v.f + log_2);
 }