Бранимир Караџић hai 1 ano
pai
achega
004821227f
Modificáronse 3 ficheiros con 30 adicións e 30 borrados
  1. 7 7
      include/bx/inline/math.inl
  2. 7 7
      include/bx/math.h
  3. 16 16
      tests/math_test.cpp

+ 7 - 7
include/bx/inline/math.inl

@@ -44,7 +44,7 @@ namespace bx
 		return bitCast<double>(_a);
 		return bitCast<double>(_a);
 	}
 	}
 
 
-	inline BX_CONST_FUNC uint32_t floatFlip(uint32_t _value)
+	inline BX_CONSTEXPR_FUNC uint32_t floatFlip(uint32_t _value)
 	{
 	{
 		// Reference(s):
 		// Reference(s):
 		// - http://archive.fo/2012.12.08-212402/http://stereopsis.com/radix.html
 		// - http://archive.fo/2012.12.08-212402/http://stereopsis.com/radix.html
@@ -56,37 +56,37 @@ namespace bx
 		return result;
 		return result;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isNan(float _f)
+	inline BX_CONSTEXPR_FUNC bool isNan(float _f)
 	{
 	{
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		return tmp > kFloatExponentMask;
 		return tmp > kFloatExponentMask;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isNan(double _f)
+	inline BX_CONSTEXPR_FUNC bool isNan(double _f)
 	{
 	{
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		return tmp > kDoubleExponentMask;
 		return tmp > kDoubleExponentMask;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isFinite(float _f)
+	inline BX_CONSTEXPR_FUNC bool isFinite(float _f)
 	{
 	{
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		return tmp < kFloatExponentMask;
 		return tmp < kFloatExponentMask;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isFinite(double _f)
+	inline BX_CONSTEXPR_FUNC bool isFinite(double _f)
 	{
 	{
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		return tmp < kDoubleExponentMask;
 		return tmp < kDoubleExponentMask;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isInfinite(float _f)
+	inline BX_CONSTEXPR_FUNC bool isInfinite(float _f)
 	{
 	{
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		const uint32_t tmp = floatToBits(_f) & INT32_MAX;
 		return tmp == kFloatExponentMask;
 		return tmp == kFloatExponentMask;
 	}
 	}
 
 
-	inline BX_CONST_FUNC bool isInfinite(double _f)
+	inline BX_CONSTEXPR_FUNC bool isInfinite(double _f)
 	{
 	{
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		const uint64_t tmp = doubleToBits(_f) & INT64_MAX;
 		return tmp == kDoubleExponentMask;
 		return tmp == kDoubleExponentMask;

+ 7 - 7
include/bx/math.h

@@ -124,31 +124,31 @@ namespace bx
 
 
 	/// Returns sortable floating point value.
 	/// Returns sortable floating point value.
 	///
 	///
-	BX_CONST_FUNC uint32_t floatFlip(uint32_t _value);
+	BX_CONSTEXPR_FUNC uint32_t floatFlip(uint32_t _value);
 
 
 	/// Returns true if _f is a number that is NaN.
 	/// Returns true if _f is a number that is NaN.
 	///
 	///
-	BX_CONST_FUNC bool isNan(float _f);
+	BX_CONSTEXPR_FUNC bool isNan(float _f);
 
 
 	/// Returns true if _f is a number that is NaN.
 	/// Returns true if _f is a number that is NaN.
 	///
 	///
-	BX_CONST_FUNC bool isNan(double _f);
+	BX_CONSTEXPR_FUNC bool isNan(double _f);
 
 
 	/// Returns true if _f is not infinite and is not a NaN.
 	/// Returns true if _f is not infinite and is not a NaN.
 	///
 	///
-	BX_CONST_FUNC bool isFinite(float _f);
+	BX_CONSTEXPR_FUNC bool isFinite(float _f);
 
 
 	/// Returns true if _f is not infinite and is not a NaN.
 	/// Returns true if _f is not infinite and is not a NaN.
 	///
 	///
-	BX_CONST_FUNC bool isFinite(double _f);
+	BX_CONSTEXPR_FUNC bool isFinite(double _f);
 
 
 	/// Returns true if _f is infinite and is not a NaN.
 	/// Returns true if _f is infinite and is not a NaN.
 	///
 	///
-	BX_CONST_FUNC bool isInfinite(float _f);
+	BX_CONSTEXPR_FUNC bool isInfinite(float _f);
 
 
 	/// Returns true if _f is infinite and is not a NaN.
 	/// Returns true if _f is infinite and is not a NaN.
 	///
 	///
-	BX_CONST_FUNC bool isInfinite(double _f);
+	BX_CONSTEXPR_FUNC bool isInfinite(double _f);
 
 
 	/// Returns the largest integer value not greater than _f.
 	/// Returns the largest integer value not greater than _f.
 	///
 	///

+ 16 - 16
tests/math_test.cpp

@@ -33,15 +33,15 @@ TEST_CASE("isFinite, isInfinite, isNan", "[math]")
 	}
 	}
 }
 }
 
 
-bool log2_test(float _a)
+static bool testLog2(float _a)
 {
 {
 	return bx::log2(_a) == bx::log(_a) * (1.0f / bx::log(2.0f) );
 	return bx::log2(_a) == bx::log(_a) * (1.0f / bx::log(2.0f) );
 }
 }
 
 
 TEST_CASE("log2", "[math][libm]")
 TEST_CASE("log2", "[math][libm]")
 {
 {
-	log2_test(0.0f);
-	log2_test(256.0f);
+	testLog2(0.0f);
+	testLog2(256.0f);
 
 
 	REQUIRE(0.0f == bx::log2(1.0f) );
 	REQUIRE(0.0f == bx::log2(1.0f) );
 	REQUIRE(1.0f == bx::log2(2.0f) );
 	REQUIRE(1.0f == bx::log2(2.0f) );
@@ -215,7 +215,7 @@ TEST_CASE("countBits", "[math]")
 }
 }
 
 
 template<typename Ty>
 template<typename Ty>
-void testFindFirstSet()
+static void testFindFirstSet()
 {
 {
 	for (uint8_t ii = 0, num = sizeof(Ty)*8; ii < num; ++ii)
 	for (uint8_t ii = 0, num = sizeof(Ty)*8; ii < num; ++ii)
 	{
 	{
@@ -257,7 +257,7 @@ TEST_CASE("findFirstSet", "[math]")
 }
 }
 
 
 template<typename Ty>
 template<typename Ty>
-void testFindLastSet()
+static void testFindLastSet()
 {
 {
 	for (uint8_t ii = 0, num = sizeof(Ty)*8; ii < num; ++ii)
 	for (uint8_t ii = 0, num = sizeof(Ty)*8; ii < num; ++ii)
 	{
 	{
@@ -306,16 +306,16 @@ TEST_CASE("rcp", "[math][libm]")
 {
 {
 	STATIC_REQUIRE(1.0f == bx::rcp(1.0f) );
 	STATIC_REQUIRE(1.0f == bx::rcp(1.0f) );
 	STATIC_REQUIRE(2.0f == bx::rcp(0.5f) );
 	STATIC_REQUIRE(2.0f == bx::rcp(0.5f) );
-	REQUIRE(bx::isInfinite(bx::rcp( 0.0f) ) );
-	REQUIRE(bx::isInfinite(bx::rcp(-0.0f) ) );
+	STATIC_REQUIRE(bx::isInfinite(bx::rcp( 0.0f) ) );
+	STATIC_REQUIRE(bx::isInfinite(bx::rcp(-0.0f) ) );
 }
 }
 
 
 TEST_CASE("rcpSafe", "[math][libm]")
 TEST_CASE("rcpSafe", "[math][libm]")
 {
 {
 	STATIC_REQUIRE(1.0f == bx::rcpSafe(1.0f) );
 	STATIC_REQUIRE(1.0f == bx::rcpSafe(1.0f) );
 	STATIC_REQUIRE(2.0f == bx::rcpSafe(0.5f) );
 	STATIC_REQUIRE(2.0f == bx::rcpSafe(0.5f) );
-	REQUIRE(!bx::isInfinite(bx::rcpSafe( 0.0f) ) );
-	REQUIRE(!bx::isInfinite(bx::rcpSafe(-0.0f) ) );
+	STATIC_REQUIRE(bx::isFinite(bx::rcpSafe( 0.0f) ) );
+	STATIC_REQUIRE(bx::isFinite(bx::rcpSafe(-0.0f) ) );
 }
 }
 
 
 TEST_CASE("rsqrt", "[math][libm]")
 TEST_CASE("rsqrt", "[math][libm]")
@@ -670,8 +670,8 @@ TEST_CASE("sign", "[math][libm]")
 	STATIC_REQUIRE( 0 == bx::sign( 0.0000f) );
 	STATIC_REQUIRE( 0 == bx::sign( 0.0000f) );
 	STATIC_REQUIRE( 1 == bx::sign( 0.1389f) );
 	STATIC_REQUIRE( 1 == bx::sign( 0.1389f) );
 
 
-	REQUIRE(-1 == bx::sign(-bx::kFloatInfinity) );
-	REQUIRE( 1 == bx::sign( bx::kFloatInfinity) );
+	STATIC_REQUIRE(-1 == bx::sign(-bx::kFloatInfinity) );
+	STATIC_REQUIRE( 1 == bx::sign( bx::kFloatInfinity) );
 }
 }
 
 
 TEST_CASE("signBit", "[math][libm]")
 TEST_CASE("signBit", "[math][libm]")
@@ -680,8 +680,8 @@ TEST_CASE("signBit", "[math][libm]")
 	STATIC_REQUIRE(!bx::signBit( 0.0000f) );
 	STATIC_REQUIRE(!bx::signBit( 0.0000f) );
 	STATIC_REQUIRE(!bx::signBit( 0.1389f) );
 	STATIC_REQUIRE(!bx::signBit( 0.1389f) );
 
 
-	REQUIRE( bx::signBit(-bx::kFloatInfinity) );
-	REQUIRE(!bx::signBit( bx::kFloatInfinity) );
+	STATIC_REQUIRE( bx::signBit(-bx::kFloatInfinity) );
+	STATIC_REQUIRE(!bx::signBit( bx::kFloatInfinity) );
 }
 }
 
 
 TEST_CASE("copySign", "[math][libm]")
 TEST_CASE("copySign", "[math][libm]")
@@ -690,13 +690,13 @@ TEST_CASE("copySign", "[math][libm]")
 	STATIC_REQUIRE(-0.0000f == bx::copySign( 0.0000f, -1389) );
 	STATIC_REQUIRE(-0.0000f == bx::copySign( 0.0000f, -1389) );
 	STATIC_REQUIRE(-0.1389f == bx::copySign( 0.1389f, -1389) );
 	STATIC_REQUIRE(-0.1389f == bx::copySign( 0.1389f, -1389) );
 
 
-	REQUIRE(-bx::kFloatInfinity == bx::copySign(bx::kFloatInfinity, -1389) );
+	STATIC_REQUIRE(-bx::kFloatInfinity == bx::copySign(bx::kFloatInfinity, -1389) );
 }
 }
 
 
 TEST_CASE("bitsToFloat, floatToBits, bitsToDouble, doubleToBits", "[math]")
 TEST_CASE("bitsToFloat, floatToBits, bitsToDouble, doubleToBits", "[math]")
 {
 {
-	REQUIRE(UINT32_C(0x12345678)         == bx::floatToBits( bx::bitsToFloat( UINT32_C(0x12345678) ) ) );
-	REQUIRE(UINT64_C(0x123456789abcdef0) == bx::doubleToBits(bx::bitsToDouble(UINT32_C(0x123456789abcdef0) ) ) );
+	STATIC_REQUIRE(0x12345678u           == bx::floatToBits( bx::bitsToFloat (0x12345678u) ) );
+	STATIC_REQUIRE(0x123456789abcdef0llu == bx::doubleToBits(bx::bitsToDouble(0x123456789abcdef0llu) ) );
 }
 }
 
 
 TEST_CASE("lerp", "[math]")
 TEST_CASE("lerp", "[math]")