Parcourir la source

[cs] Math.round correct behavior for -1.5

Caue Waneck il y a 13 ans
Parent
commit
566a4c1ad0
1 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 11 3
      std/cs/_std/Math.hx

+ 11 - 3
std/cs/_std/Math.hx

@@ -69,9 +69,17 @@ import system.Random;
 		return system.Math.Sqrt(v);
 	}
 	
-	public static inline function round(v:Float):Int
-	{
-		return Std.int(system.Math.Round(v));
+	public static function round(v:Float):Int
+	{
+		var vint = Std.int(v);
+		var dec = v - vint;
+		if (dec >= 1 || dec <= -1)
+			return vint; //overflow
+		if (dec >= .5)
+			return vint + 1;
+		if (dec < -.5)
+			return vint - 1;
+		return vint;
 	}
 	
 	public static inline function floor(v:Float):Int