From bc95ec8084764b78cd4db58217c7cbe4c1009341 Mon Sep 17 00:00:00 2001 From: frohlich Date: Sat, 17 Jun 2006 16:04:28 +0000 Subject: [PATCH] Make at least the header aliasing safe. --- simgear/math/fastmath.hxx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) 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); } -- 2.39.5