فهرست منبع

fixed min/max with NaN on neko, more into to floats

Nicolas Cannasse 12 سال پیش
والد
کامیت
5f303d004c
2فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 2 2
      std/neko/_std/Math.hx
  2. 12 1
      tests/unit/TestBasetypes.hx

+ 2 - 2
std/neko/_std/Math.hx

@@ -28,8 +28,8 @@ import neko.Lib;
 	public static var POSITIVE_INFINITY(default,null) : Float;
 	public static var NEGATIVE_INFINITY(default,null) : Float;
 
-	public static function min(a:Float,b:Float) : Float { return if( a < b ) a else b; }
-	public static function max(a:Float,b:Float) : Float { return if( a < b ) b else a; }
+	public static function min(a:Float,b:Float) : Float { return if( a < b ) a else if( untyped $isnan(a) ) a else b; }
+	public static function max(a:Float,b:Float) : Float { return if( a < b ) b else if( untyped $isnan(b) ) b else a; }
 
 	public static function abs( v : Float ) : Float return 0.;
 	public static function sin( v : Float ) : Float return 0.;

+ 12 - 1
tests/unit/TestBasetypes.hx

@@ -162,7 +162,18 @@ class TestBasetypes extends Test {
 
 
 		eq( Std.int( -10000000000.7), 0xABF41C00 );
-
+		
+		// int/uint limit values
+		eq( Std.int( -4294967296.7), 0 );
+		eq( Std.int( 4294967296.7), 0 );
+		eq( Std.int( -4294967295.7), 1 );
+		eq( Std.int( 4294967295.7), -1 );
+
+		eq( Std.int( -2147483648.7), 0x80000000 );
+		eq( Std.int( 2147483648.7), 0x80000000 );
+		eq( Std.int( -2147483647.7), 0x80000001 );
+		eq( Std.int( 2147483647.7), 0x7FFFFFFF );
+		
 		#if (js || flash8 || as3 || php)
 
 		// higher Int resolution : should we fix this or not ?