Browse Source

[cs] fix Math.fround, add tests for it (closes #4177)

Dan Korostelev 10 years ago
parent
commit
bddfbc22fa
2 changed files with 16 additions and 1 deletions
  1. 1 1
      std/cs/_std/Math.hx
  2. 15 0
      tests/unit/src/unitstd/Math.unit.hx

+ 1 - 1
std/cs/_std/Math.hx

@@ -85,7 +85,7 @@
 
 	public static inline function fround(v:Float):Float
 	{
-		return cs.system.Math.Round(v);
+		return cs.system.Math.Floor(v + 0.5);
 	}
 
 	public static inline function ffloor(v:Float):Float

+ 15 - 0
tests/unit/src/unitstd/Math.unit.hx

@@ -170,6 +170,21 @@ Math.round( -1.50001) == -2;
 Math.fround(Math.POSITIVE_INFINITY) == Math.POSITIVE_INFINITY;
 Math.fround(Math.NEGATIVE_INFINITY) == Math.NEGATIVE_INFINITY;
 Math.isNaN(Math.fround(Math.NaN)) == true;
+Math.fround(0.0) == 0.0;
+Math.fround(0.1) == 0.0;
+Math.fround(0.4999) == 0.0;
+Math.fround(0.5) == 1.0;
+Math.fround(1.0) == 1.0;
+Math.fround(1.499) == 1.0;
+Math.fround(1.5) == 2.0;
+Math.fround(-0.1) == -0.0;
+Math.fround(-0.4999) == -0.0;
+Math.fround(-0.5) == -0.0;
+Math.fround(-0.50001) == -1.0;
+Math.fround(-1.0) == -1.0;
+Math.fround(-1.499) == -1.0;
+Math.fround(-1.5) == -1.0;
+Math.fround( -1.50001) == -2.0;
 
 // floor
 Math.floor(0.0) == 0;