From b43eb8259fab60deeab4928d4371e3adeb5ae3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 14 Nov 2024 21:24:24 -0800 Subject: [PATCH] Cleanup. --- include/bx/constants.h | 6 +++--- include/bx/inline/bx.inl | 3 +++ include/bx/inline/math.inl | 20 ++++++++------------ include/bx/math.h | 8 ++++---- src/math.cpp | 3 --- tests/cast_test.cpp | 1 - 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/bx/constants.h b/include/bx/constants.h index 5d8d011..06b0ee1 100644 --- a/include/bx/constants.h +++ b/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 diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index ef0933c..2fdd8ca 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -176,4 +176,7 @@ namespace bx return to; } + constexpr float kFloatInfinity = bitCast(kFloatExponentMask); + constexpr double kDoubleInfinity = bitCast(kDoubleExponentMask); + } // namespace bx diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index 0d19de2..19932f3 100644 --- a/include/bx/inline/math.inl +++ b/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(_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(_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(_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(_a); } inline BX_CONST_FUNC uint32_t floatFlip(uint32_t _value) diff --git a/include/bx/math.h b/include/bx/math.h index 21cf660..51c571a 100644 --- a/include/bx/math.h +++ b/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. /// diff --git a/src/math.cpp b/src/math.cpp index b26d1b4..52cafd9 100644 --- a/src/math.cpp +++ b/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; diff --git a/tests/cast_test.cpp b/tests/cast_test.cpp index b4163cf..2a1eda9 100644 --- a/tests/cast_test.cpp +++ b/tests/cast_test.cpp @@ -5,7 +5,6 @@ #include "test.h" #include -#include TEST_CASE("Bit cast", "[cast]") {