diff --git a/src/math.cpp b/src/math.cpp index 2be642d..cffe8c6 100644 --- a/src/math.cpp +++ b/src/math.cpp @@ -124,6 +124,12 @@ namespace bx const float ay = abs(_y); const float maxaxy = max(ax, ay); const float minaxy = min(ax, ay); + + if (maxaxy == 0.0f) + { + return 0.0f*sign(_y); + } + const float mxy = minaxy / maxaxy; const float mxysq = square(mxy); const float tmp0 = mad(kAtan2C0, mxysq, kAtan2C1); diff --git a/tests/math_test.cpp b/tests/math_test.cpp index decca45..f6ef5c7 100644 --- a/tests/math_test.cpp +++ b/tests/math_test.cpp @@ -144,6 +144,8 @@ TEST_CASE("libm", "") REQUIRE(bx::equal(bx::atan2(yy, xx), ::atan2f(yy, xx), 0.00001f) ); } } + + REQUIRE(bx::equal(bx::atan2(0.0f, 0.0f), ::atan2f(0.0f, 0.0f), 0.00001f) ); } TEST_CASE("ToBits", "")