Browse Source

fixed large integers

Nicolas Cannasse 17 years ago
parent
commit
b744028ad3
5 changed files with 9 additions and 5 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 2 3
      std/Type.hx
  3. 1 1
      std/flash/Boot.hx
  4. 1 1
      std/js/Boot.hx
  5. 4 0
      tests/unit/TestReflect.hx

+ 1 - 0
doc/CHANGES.txt

@@ -10,6 +10,7 @@
 	fixed handling of implements ArrayAccess
 	fixed some minor things in flash10 api
 	switch/for/while/do/try/if are no longer using parse_next (parenthesises requ. instead)
+	fixed Type.typeof and Std.is in case of too much large integers for Flash6-8/JS
 
 2008-10-04: 2.01
 	fixed php.Sys

+ 2 - 3
std/Type.hx

@@ -557,9 +557,8 @@ class Type {
 			case "boolean": return TBool;
 			case "string": return TClass(String);
 			case "number":
-				if( v+1 == v )
-					return TFloat;
-				if( Math.ceil(v) == v )
+				// this should handle all cases : NaN, +/-Inf and Floats outside range
+				if( Math.ceil(v) == v%2147483648.0 )
 					return TInt;
 				return TFloat;
 			case "object":

+ 1 - 1
std/flash/Boot.hx

@@ -138,7 +138,7 @@ class Boot {
 			#end
 			switch( cast cl ) {
 			case Int:
-				return __physeq__(Math.ceil(o),o) && isFinite(o) && !(__physeq__(o,true) || __physeq__(o,false));
+				return __physeq__(Math.ceil(o),o%2147483648.0) && !(__physeq__(o,true) || __physeq__(o,false));
 			case Float:
 				return __typeof__(o) == "number";
 			case Bool:

+ 1 - 1
std/js/Boot.hx

@@ -174,7 +174,7 @@ class Boot {
 			}
 			switch( cl ) {
 			case Int:
-				return __js__("Math.ceil(o) === o") && isFinite(o);
+				return __js__("Math.ceil(o%2147483648.0) === o");
 			case Float:
 				return __js__("typeof(o)") == "number";
 			case Bool:

+ 4 - 0
tests/unit/TestReflect.hx

@@ -59,6 +59,8 @@ class TestReflect extends Test {
 		is(1,Int,Float);
 		is(-1,Int,Float);
 		is(1.2,Float);
+		is(1e10,Float);
+		is(-1e10,Float);
 		is(Math.NaN,Float);
 		is(Math.POSITIVE_INFINITY,Float);
 		is(Math.NEGATIVE_INFINITY,Float);
@@ -100,6 +102,8 @@ class TestReflect extends Test {
 		typeof(1,TInt);
 		typeof(-1,TInt);
 		typeof(1.2,TFloat);
+		typeof(1e10,TFloat);
+		typeof(-1e10,TFloat);
 		typeof(Math.NaN,TFloat);
 		typeof(Math.POSITIVE_INFINITY,TFloat);
 		typeof(Math.NEGATIVE_INFINITY,TFloat);