diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index 00ec324..d6b8c57 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -45,6 +45,17 @@ namespace bx return u.f; } + inline uint32_t floatFlip(uint32_t _value) + { + // Reference: + // http://archive.fo/2012.12.08-212402/http://stereopsis.com/radix.html + const uint32_t tmp0 = uint32_sra(_value, 31); + const uint32_t tmp1 = uint32_neg(tmp0); + const uint32_t mask = uint32_or(tmp1, 0x80000000); + const uint32_t result = uint32_xor(_value, mask); + return result; + } + inline bool isNan(float _f) { const uint32_t tmp = floatToBits(_f) & INT32_MAX; diff --git a/include/bx/math.h b/include/bx/math.h index cc0ffb0..66b0a51 100644 --- a/include/bx/math.h +++ b/include/bx/math.h @@ -9,6 +9,7 @@ #define BX_FPU_MATH_H_HEADER_GUARD #include "bx.h" +#include "uint32_t.h" namespace bx { @@ -61,6 +62,9 @@ namespace bx /// double bitsToDouble(uint64_t _a); + /// + uint32_t floatFlip(uint32_t _value); + /// bool isNan(float _f);