Бранимир Караџић пре 1 година
родитељ
комит
b43eb8259f
6 измењених фајлова са 18 додато и 23 уклоњено
  1. 3 3
      include/bx/constants.h
  2. 3 0
      include/bx/inline/bx.inl
  3. 8 12
      include/bx/inline/math.inl
  4. 4 4
      include/bx/math.h
  5. 0 3
      src/math.cpp
  6. 0 1
      tests/cast_test.cpp

+ 3 - 3
include/bx/constants.h

@@ -84,7 +84,7 @@ namespace bx
 	constexpr float    kFloatLargest   = 3.402823466e+38f;
 
 	///
-	extern const float kFloatInfinity;
+//	constexpr float    kFloatInfinity;
 
 	///
 	constexpr uint8_t  kDoubleSignNumBits     = 1;
@@ -104,8 +104,8 @@ namespace bx
 	/// Largest representable double-precision floating-point number.
 	constexpr double   kDoubleLargest  = 1.7976931348623158e+308;
 
-	///
-	extern const double kDoubleInfinity;
+	//
+//	constexpr double   kDoubleInfinity;
 
 } // namespace bx
 

+ 3 - 0
include/bx/inline/bx.inl

@@ -176,4 +176,7 @@ namespace bx
 		return to;
 	}
 
+	constexpr float  kFloatInfinity  = bitCast<float>(kFloatExponentMask);
+	constexpr double kDoubleInfinity = bitCast<double>(kDoubleExponentMask);
+
 } // namespace bx

+ 8 - 12
include/bx/inline/math.inl

@@ -24,28 +24,24 @@ namespace bx
 		return _rad * 180.0f / kPi;
 	}
 
-	inline BX_CONST_FUNC uint32_t floatToBits(float _a)
+	inline BX_CONSTEXPR_FUNC uint32_t floatToBits(float _a)
 	{
-		union { float f; uint32_t ui; } u = { _a };
-		return u.ui;
+		return bitCast<uint32_t>(_a);
 	}
 
-	inline BX_CONST_FUNC float bitsToFloat(uint32_t _a)
+	inline BX_CONSTEXPR_FUNC float bitsToFloat(uint32_t _a)
 	{
-		union { uint32_t ui; float f; } u = { _a };
-		return u.f;
+		return bitCast<float>(_a);
 	}
 
-	inline BX_CONST_FUNC uint64_t doubleToBits(double _a)
+	inline BX_CONSTEXPR_FUNC uint64_t doubleToBits(double _a)
 	{
-		union { double f; uint64_t ui; } u = { _a };
-		return u.ui;
+		return bitCast<uint64_t>(_a);
 	}
 
-	inline BX_CONST_FUNC double bitsToDouble(uint64_t _a)
+	inline BX_CONSTEXPR_FUNC double bitsToDouble(uint64_t _a)
 	{
-		union { uint64_t ui; double f; } u = { _a };
-		return u.f;
+		return bitCast<double>(_a);
 	}
 
 	inline BX_CONST_FUNC uint32_t floatFlip(uint32_t _value)

+ 4 - 4
include/bx/math.h

@@ -108,19 +108,19 @@ namespace bx
 
 	/// Reinterprets the bit pattern of _a as uint32_t.
 	///
-	BX_CONST_FUNC uint32_t floatToBits(float _a);
+	BX_CONSTEXPR_FUNC uint32_t floatToBits(float _a);
 
 	/// Reinterprets the bit pattern of _a as float.
 	///
-	BX_CONST_FUNC float bitsToFloat(uint32_t _a);
+	BX_CONSTEXPR_FUNC float bitsToFloat(uint32_t _a);
 
 	/// Reinterprets the bit pattern of _a as uint64_t.
 	///
-	BX_CONST_FUNC uint64_t doubleToBits(double _a);
+	BX_CONSTEXPR_FUNC uint64_t doubleToBits(double _a);
 
 	/// Reinterprets the bit pattern of _a as double.
 	///
-	BX_CONST_FUNC double bitsToDouble(uint64_t _a);
+	BX_CONSTEXPR_FUNC double bitsToDouble(uint64_t _a);
 
 	/// Returns sortable floating point value.
 	///

+ 0 - 3
src/math.cpp

@@ -10,9 +10,6 @@
 
 namespace bx
 {
-	const float  kFloatInfinity  = bitsToFloat(kFloatExponentMask);
-	const double kDoubleInfinity = bitsToDouble(kDoubleExponentMask);
-
 	namespace
 	{
 		constexpr float kSinC2  = -0.16666667163372039794921875f;

+ 0 - 1
tests/cast_test.cpp

@@ -5,7 +5,6 @@
 
 #include "test.h"
 #include <bx/bx.h>
-#include <string.h>
 
 TEST_CASE("Bit cast", "[cast]")
 {