From 7a05d193521528f81302e9d73de94a26f2f75dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 23 Apr 2018 16:22:14 -0700 Subject: [PATCH] Fixed atan2. --- src/math.cpp | 6 ++++++ tests/math_test.cpp | 2 ++ 2 files changed, 8 insertions(+) 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", "")