From ce5808f572d6f25bdb3a30fddb910dbd44c53fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 7 Nov 2017 20:30:35 -0800 Subject: [PATCH] Moved floatFlip from bgfx to bx. --- include/bx/inline/math.inl | 11 +++++++++++ include/bx/math.h | 4 ++++ 2 files changed, 15 insertions(+) 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);