diff --git a/add_on/scriptmath/scriptmath.cpp b/add_on/scriptmath/scriptmath.cpp index 5144dcb..0ffe7c3 100644 --- a/add_on/scriptmath/scriptmath.cpp +++ b/add_on/scriptmath/scriptmath.cpp @@ -72,6 +72,16 @@ double fraction(double v) } #endif +template +struct alias_cast_t +{ + union + { + F raw; + T data; + }; +}; + // As AngelScript doesn't allow bitwise manipulation of float types we'll provide a couple of // functions for converting float values to IEEE 754 formatted values etc. This also allow us to // provide a platform agnostic representation to the script so the scripts don't have to worry @@ -80,19 +90,27 @@ float fpFromIEEE(asUINT raw) { // TODO: Identify CPU family to provide proper conversion // if the CPU doesn't natively use IEEE style floats - return *reinterpret_cast(&raw); + alias_cast_t t; + t.raw = raw; + return t.data; } asUINT fpToIEEE(float fp) { - return *reinterpret_cast(&fp); + alias_cast_t t; + t.raw = fp; + return t.data; } double fpFromIEEE(asQWORD raw) { - return *reinterpret_cast(&raw); + alias_cast_t t; + t.raw = raw; + return t.data; } asQWORD fpToIEEE(double fp) { - return *reinterpret_cast(&fp); + alias_cast_t t; + t.raw = fp; + return t.data; } // closeTo() is used to determine if the binary representation of two numbers are