Branimir Karadžić 7 år sedan
förälder
incheckning
7a05d19352
2 ändrade filer med 8 tillägg och 0 borttagningar
  1. 6 0
      src/math.cpp
  2. 2 0
      tests/math_test.cpp

+ 6 - 0
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);

+ 2 - 0
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", "")