Explorar el Código

Avoid duplication of code for the float-to-raw-unsigned-bits conversion.

Lasse Öörni hace 8 años
padre
commit
3b799b7712
Se han modificado 1 ficheros con 9 adiciones y 15 borrados
  1. 9 15
      Source/Urho3D/Math/MathDefs.h

+ 9 - 15
Source/Urho3D/Math/MathDefs.h

@@ -91,6 +91,13 @@ inline T Abs(T value) { return value >= 0.0 ? value : -value; }
 template <class T>
 inline T Sign(T value) { return value > 0.0 ? 1.0 : (value < 0.0 ? -1.0 : 0.0); }
 
+/// Return a representation of the specified floating-point value as a single format bit layout.
+inline unsigned FloatToRawIntBits(float value)
+{
+    unsigned u = *((unsigned*)&value);
+    return u;
+}
+
 /// Check whether a floating point value is NaN.
 /// Use a workaround for GCC, see https://github.com/urho3d/Urho3D/issues/655
 #ifndef __GNUC__
@@ -99,7 +106,7 @@ inline bool IsNaN(float value) { return value != value; }
 
 inline bool IsNaN(float value)
 {
-    unsigned u = *(unsigned*)(&value);
+    unsigned u = FloatToRawIntBits(value);
     return (u & 0x7fffffff) > 0x7f800000;
 }
 
@@ -232,7 +239,7 @@ inline float RandomNormal(float meanValue, float variance) { return RandStandard
 /// Convert float to half float. From https://gist.github.com/martinkallman/5049614
 inline unsigned short FloatToHalf(float value)
 {
-    unsigned inu = *((unsigned*)&value);
+    unsigned inu = FloatToRawIntBits(value);
     unsigned t1 = inu & 0x7fffffff;         // Non-sign bits
     unsigned t2 = inu & 0x80000000;         // Sign bit
     unsigned t3 = inu & 0x7f800000;         // Exponent
@@ -272,19 +279,6 @@ inline float HalfToFloat(unsigned short value)
     return out;
 }
 
-// Returns a representation of the specified floating-point value as a single format bit layout.
-inline unsigned FloatToRawIntBits(float x)
-{
-    union
-    {
-        unsigned i;
-        float x;
-    } u;
-
-    u.x = x;
-    return u.i;
-}
-
 /// Calculate both sine and cosine, with angle in degrees.
 URHO3D_API void SinCos(float angle, float& sin, float& cos);