Browse Source

fixed haxe.Int32.mul overflow on 52 bits

Nicolas Cannasse 13 years ago
parent
commit
31f92efc48
3 changed files with 12 additions and 1 deletions
  1. 4 0
      doc/CHANGES.txt
  2. 4 0
      std/haxe/Int32.hx
  3. 4 1
      tests/unit/TestInt32.hx

+ 4 - 0
doc/CHANGES.txt

@@ -1,6 +1,10 @@
 2012-??-??: 3.0
 	flash : fixed Xml.parent exception if parent does not exists
 	all : fixed List and Null<T> for first, last, pop
+	js : added js.Lib.debug()
+	flash : fixed Xml.parent() when no parent
+	flash : fixed haxe.io.Bytes.blit when len=0
+	js/php/flash8 : fixed haxe.Int32.mul overflow on 52 bits
 
 2012-04-14: 2.09
 	all : optimized const == const and const != const (with different const types)

+ 4 - 0
std/haxe/Int32.hx

@@ -64,7 +64,11 @@ class Int32 {
 	}
 
 	public static inline function mul( a : Int32, b : Int32 ) : Int32 {
+		#if (flash8 || php || js)
+		return add(cast ((cast a) * ((cast b) & 0xFFFF)),clamp(cast ((cast a) * ((cast b) >>> 16) << 16)));
+		#else
 		return clamp(cast ((cast a) * (cast b)));
+		#end
 	}
 
 	public static inline function div( a : Int32, b : Int32 ) : Int32 {

+ 4 - 1
tests/unit/TestInt32.hx

@@ -59,7 +59,10 @@ class TestInt32 extends Test {
 		eq( i(Int32.mul(i32(5),i32(100))), 500 );
 
 		// overflow
-		eq( i(Int32.mul(i32(160427),i32(160427))), 0xFE08BE39 );
+		eq( i(Int32.mul(i32(160427), i32(160427))), 0xFE08BE39 );
+		
+		// float overflow
+		eq( i(Int32.mul(f(0x811C,0x9DAE), i32(16777619))), -301188886 );
 
 		// signed divide and modulo
 		eq( i(Int32.div(i32(0x3E08BE39),i32(16))), 0x03E08BE3 );