Explorar o código

handle positive and negative infinity in trigonometry functions

frabbit %!s(int64=11) %!d(string=hai) anos
pai
achega
21787502b4
Modificáronse 1 ficheiros con 15 adicións e 5 borrados
  1. 15 5
      std/python/_std/Math.hx

+ 15 - 5
std/python/_std/Math.hx

@@ -149,11 +149,21 @@ extern class Math
 	}
 
 
-	static function tan(v:Float):Float;
-	static function asin(v:Float):Float;
-	static function acos(v:Float):Float;
-	static function atan(v:Float):Float;
-	static function atan2(y:Float, x:Float):Float;
+	static function tan(v:Float):Float {
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.tan(v);
+	}
+	static function asin(v:Float):Float {
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.asin(v);
+	}
+	static function acos(v:Float):Float {
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.acos(v);
+	}
+	static function atan(v:Float):Float {
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.atan(v);
+	}
+	static function atan2(y:Float, x:Float):Float {
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.atan2(v);
+	}
 
 	/**
 		Returns Euler's number, raised to the power of `v`.