Browse Source

Fixed atan2. Issue #282. Caused by 7929f098f559af2ea7cc440fef2a7eae51d9a6fc.

Бранимир Караџић 3 years ago
parent
commit
7d784e74ff
2 changed files with 12 additions and 5 deletions
  1. 1 1
      src/math.cpp
  2. 11 4
      tests/math_test.cpp

+ 1 - 1
src/math.cpp

@@ -125,7 +125,7 @@ namespace bx
 		const float tmp5   = tmp4 * mxy;
 		const float tmp6   = ay > ax   ? kPiHalf - tmp5 : tmp5;
 		const float tmp7   = _x < 0.0f ? kPi     - tmp6 : tmp6;
-		const float result = sign(_y)*tmp7;
+		const float result = (_y < 0.0f ? -1.0f : 1.0f)*tmp7;
 
 		return result;
 	}

+ 11 - 4
tests/math_test.cpp

@@ -63,6 +63,7 @@ TEST_CASE("log2", "")
 TEST_CASE("libm", "")
 {
 	bx::WriterI* writer = bx::getNullOut();
+	bx::Error err;
 
 	REQUIRE(1389.0f == bx::abs(-1389.0f) );
 	REQUIRE(1389.0f == bx::abs( 1389.0f) );
@@ -81,8 +82,6 @@ TEST_CASE("libm", "")
 	REQUIRE(bx::isEqual( 0.89f, bx::fract( 13.89f), 0.000001f) );
 	REQUIRE(bx::isEqual(-0.89f, bx::fract(-13.89f), 0.000001f) );
 
-	bx::Error err;
-
 	for (int32_t yy = -10; yy < 10; ++yy)
 	{
 		for (float xx = -100.0f; xx < 100.0f; xx += 0.1f)
@@ -196,6 +195,16 @@ TEST_CASE("libm", "")
 		REQUIRE(err.isOk() );
 		REQUIRE(bx::isEqual(bx::atan(xx), ::atanf(xx), 0.00001f) );
 	}
+}
+
+TEST_CASE("atan2", "")
+{
+	bx::WriterI* writer = bx::getNullOut();
+	bx::Error err;
+
+	REQUIRE(bx::isEqual(bx::atan2(0.0f,  0.0f), ::atan2f(0.0f,  0.0f), 0.00001f) );
+	REQUIRE(bx::isEqual(bx::atan2(0.0f,  1.0f), ::atan2f(0.0f,  1.0f), 0.00001f) );
+	REQUIRE(bx::isEqual(bx::atan2(0.0f, -1.0f), ::atan2f(0.0f, -1.0f), 0.00001f) );
 
 	for (float yy = -100.0f; yy < 100.0f; yy += 0.1f)
 	{
@@ -206,8 +215,6 @@ TEST_CASE("libm", "")
 			REQUIRE(bx::isEqual(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) );
 		}
 	}
-
-	REQUIRE(bx::isEqual(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) );
 }
 
 TEST_CASE("sign", "")