From: frohlich <frohlich>
Date: Sat, 17 Jun 2006 16:04:28 +0000 (+0000)
Subject: Make at least the header aliasing safe.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bc95ec8084764b78cd4db58217c7cbe4c1009341;p=simgear.git

Make at least the header aliasing safe.
---

diff --git a/simgear/math/fastmath.hxx b/simgear/math/fastmath.hxx
index f78fddc5..b84f3e92 100644
--- a/simgear/math/fastmath.hxx
+++ b/simgear/math/fastmath.hxx
@@ -97,19 +97,34 @@ inline float fast_pow(const float val1, const float val2)
  */
 inline float fast_abs(float f)
 {
-    int i=((*(int*)&f)&0x7fffffff);
-    return (*(float*)&i);
+    union {
+        float f;
+        int i;
+    } v;
+    v.f = f;
+    v.i = v.i&0x7fffffff;
+    return v.f;
 }
 
 inline float fast_neg(float f)
 {
-    int i=((*(int*)&f)^0x80000000);
-    return (*(float*)&i);
+    union {
+        float f;
+        int i;
+    } v;
+    v.f = f;
+    v.i = v.i^0x80000000;
+    return v.f;
 }
 
 inline int fast_sgn(float f)
 {
-    return 1+(((*(int*)&f)>>31)<<1);
+    union {
+        float f;
+        int i;
+    } v;
+    v.f = f;
+    return 1+((v.i>>31)<<1);
 }