Browse Source

php: fixed float to int32 conversion

Franco Ponticelli 12 years ago
parent
commit
16879eb58f
3 changed files with 6 additions and 2 deletions
  1. 4 0
      genphp.ml
  2. 1 1
      std/php/_std/Std.hx
  3. 1 1
      tests/unit/TestBasetypes.hx

+ 4 - 0
genphp.ml

@@ -580,6 +580,10 @@ and gen_call ctx e el =
 		spr ctx " === ";
 		spr ctx " === ";
 		gen_value ctx e2;
 		gen_value ctx e2;
 		spr ctx ")"
 		spr ctx ")"
+	| TLocal { v_name = "__int32__" },  [e1] ->
+		spr ctx "((";
+		gen_value ctx e1;
+		spr ctx " | 0) % 0x80000000)"
 	| TLocal _, []
 	| TLocal _, []
 	| TFunction _, []
 	| TFunction _, []
 	| TCall _, []
 	| TCall _, []

+ 1 - 1
std/php/_std/Std.hx

@@ -30,7 +30,7 @@
 	}
 	}
 
 
 	public inline static function int( x : Float ) : Int {
 	public inline static function int( x : Float ) : Int {
-		return untyped __call__("intval", x);
+		return untyped __int32__(x);
 	}
 	}
 
 
 	public static function parseInt( x : String ) : Null<Int> {
 	public static function parseInt( x : String ) : Null<Int> {

+ 1 - 1
tests/unit/TestBasetypes.hx

@@ -157,7 +157,7 @@ class TestBasetypes extends Test {
 
 
 		eq( Std.int( -10000000000.7), 0xABF41C00 );
 		eq( Std.int( -10000000000.7), 0xABF41C00 );
 
 
-		#if (js || flash8 || as3)
+		#if (js || flash8 || as3 || php)
 
 
 		// higher Int resolution : should we fix this or not ?
 		// higher Int resolution : should we fix this or not ?
 		eq( Math.floor( -10000000000.7)*1.0, -10000000001. );
 		eq( Math.floor( -10000000000.7)*1.0, -10000000001. );