Selaa lähdekoodia

added haxe.Int64, fixed overflows for haxe.Int32

Nicolas Cannasse 14 vuotta sitten
vanhempi
commit
22d5cfd3df

+ 2 - 0
doc/CHANGES.txt

@@ -7,6 +7,8 @@
 	all : allow macro typed parameters (other than Expr)
 	flash : added flash11 apis
 	neko : added support for https to haxe.Http (using hxssl library)
+	all : added haxe.Int64
+	all : added haxe.Int32 isNeg,isZero,ucompare, fixed overflows for js/flash8/php
 
 2011-01-30: 2.07
 	all : fixed completion support with --remap

+ 3 - 0
std/cpp/CppInt32__.hx

@@ -44,5 +44,8 @@ extern class CppInt32__ {
 	public static  function neg( a : Int32 ) : Int32;
 	public static  function complement( a : Int32 ) : Int32;
 	public static  function compare( a : Int32, b : Int32 ) : Int;
+	public static  function isNeg( a : Int32 ) : Bool;
+	public static  function isZero( a : Int32 ) : Bool;
+	public static  function ucompare( a : Int32, b : Int32 ) : Int;
 }
 

+ 27 - 0
std/cpp/_std/haxe/Int32.hx

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe;
+
+typedef Int32 = cpp.CppInt32__;

+ 32 - 102
std/haxe/Int32.hx

@@ -24,151 +24,95 @@
  */
 package haxe;
 
-#if (cpp && !xmldoc)
-typedef Int32 = cpp.CppInt32__;
-#else
-
 class Int32 {
 
 	public static inline function make( a : Int, b : Int ) : Int32 {
-		#if neko
-		return add(shl(cast a,16),cast b);
-		#else
 		return cast ((a << 16) | b);
-		#end
 	}
 
 	public static inline function ofInt( x : Int ) : Int32 {
-		#if neko
-		return untyped __i32__new(x);
+		return clamp(cast x);
+	}
+
+	static inline function clamp( x : Int32 ) : Int32 {
+		#if (js || flash8)
+		return cast ((cast x) | 0); // force to-int convertion
 		#else
-		return cast x;
+		return x;
 		#end
 	}
 
 	public static inline function toInt( x : Int32 ) : Int {
-		#if !neko
-		if( (((cast x) >> 30) & 1) != ((cast x) >>> 31) ) throw "Overflow "+x;
-		#end
-		#if neko
-		return try untyped __i32__to_int(x) catch( e : Dynamic ) throw "Overflow"+x;
-		#elseif flash9
-		return cast x;
-		#else
+		if( (((cast x) >> 30) & 1) != ((cast x) >>> 31) ) throw "Overflow " + x;
+		#if php
 		return (cast x) & 0xFFFFFFFF;
+		#else
+		return cast x;
 		#end
 	}
 
 	public static inline function toNativeInt( x : Int32 ) : Int {
-		#if neko
-		return untyped (__i32__ushr(x,8) << 8) | __i32__and(x,0xFF);
-		#else
 		return cast x;
-		#end
 	}
 
 	public static inline function add( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__add(a,b);
-		#else
-		return cast ((cast a) + (cast b));
-		#end
+		return clamp(cast ((cast a) + (cast b)));
 	}
 
 	public static inline function sub( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__sub(a,b);
-		#else
-		return cast ((cast a) - (cast b));
-		#end
+		return clamp(cast ((cast a) - (cast b)));
 	}
 
 	public static inline function mul( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__mul(a,b);
-		#else
-		return cast ((cast a) * (cast b));
-		#end
+		return clamp(cast ((cast a) * (cast b)));
 	}
 
 	public static inline function div( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__div(a,b);
-		#else
-		return cast Std.int((cast a) / (cast b));
-		#end
+		return cast Std.int(cast(a) / cast(b));
 	}
 
 	public static inline function mod( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__mod(a,b);
-		#else
-		return cast ((cast a) % (cast b));
-		#end
+		return cast (cast(a) % cast(b));
 	}
 
 	public static inline function shl( a : Int32, b : Int ) : Int32 {
-		#if neko
-		return untyped __i32__shl(a,b);
-		#else
 		return cast ((cast a) << b);
-		#end
 	}
 
 	public static inline function shr( a : Int32, b : Int ) : Int32 {
-		#if neko
-		return untyped __i32__shr(a,b);
-		#else
 		return cast ((cast a) >> b);
-		#end
 	}
 
 	public static inline function ushr( a : Int32, b : Int ) : Int32 {
-		#if neko
-		return untyped __i32__ushr(a,b);
-		#else
 		return cast ((cast a) >>> b);
-		#end
 	}
 
 	public static inline function and( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__and(a,b);
-		#else
 		return cast ((cast a) & (cast b));
-		#end
 	}
 
 	public static inline function or( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__or(a,b);
-		#else
 		return cast ((cast a) | (cast b));
-		#end
 	}
 
 	public static inline function xor( a : Int32, b : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__xor(a,b);
-		#else
 		return cast ((cast a) ^ (cast b));
-		#end
 	}
 
 	public static inline function neg( a : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__neg(a);
-		#else
 		return cast -(cast a);
-		#end
+	}
+
+	public static inline function isNeg( a : Int32 ) : Bool {
+		return (cast a) < 0;
+	}
+
+	public static inline function isZero( a : Int32 ) : Bool {
+		return (cast a) == 0;
 	}
 
 	public static inline function complement( a : Int32 ) : Int32 {
-		#if neko
-		return untyped __i32__complement(a);
-		#else
 		return cast ~(cast a);
-		#end
 	}
 
 	public static inline function compare( a : Int32, b : Int32 ) : Int {
@@ -179,27 +123,13 @@ class Int32 {
 		#end
 	}
 
-	#if neko
-	static function __init__() untyped {
-		__i32__new = neko.Lib.load("std","int32_new",1);
-		__i32__to_int = neko.Lib.load("std","int32_to_int",1);
-		__i32__add = neko.Lib.load("std","int32_add",2);
-		__i32__sub = neko.Lib.load("std","int32_sub",2);
-		__i32__mul = neko.Lib.load("std","int32_mul",2);
-		__i32__div = neko.Lib.load("std","int32_div",2);
-		__i32__mod = neko.Lib.load("std","int32_mod",2);
-		__i32__shl = neko.Lib.load("std","int32_shl",2);
-		__i32__shr = neko.Lib.load("std","int32_shr",2);
-		__i32__ushr = neko.Lib.load("std","int32_ushr",2);
-		__i32__and = neko.Lib.load("std","int32_and",2);
-		__i32__or = neko.Lib.load("std","int32_or",2);
-		__i32__xor = neko.Lib.load("std","int32_xor",2);
-		__i32__neg = neko.Lib.load("std","int32_neg",1);
-		__i32__complement = neko.Lib.load("std","int32_complement",1);
-		__i32__compare = neko.Lib.load("std","int32_compare",2);
-	}
-	#end
+	/**
+		Compare two Int32 in unsigned mode.
+	**/
+	public static function ucompare( a : Int32, b : Int32 ) : Int {
+		if( isNeg(a) )
+			return isNeg(b) ? compare(complement(b),complement(a)) : 1;
+		return isNeg(b) ? -1 : compare(a,b);
+	}
 
 }
-#end
-

+ 216 - 0
std/haxe/Int64.hx

@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe;
+using haxe.Int32;
+
+class Int64 {
+
+	var high : Int32;
+	var low : Int32;
+
+	function new(high, low) {
+		this.high = high;
+		this.low = low;
+	}
+
+	function toString() {
+		var str = "";
+		var neg = false;
+		var i = this;
+		if( isNeg(i) ) {
+			neg = true;
+			i = Int64.neg(i);
+		}
+		var ten = ofInt(10);
+		while( !isZero(i) ) {
+			var r = divMod(i, ten);
+			str = r.modulus.low.toInt() + str;
+			i = r.quotient;
+		}
+		if( neg ) str = "-" + str;
+		return str;
+	}
+
+	public static inline function make( high : Int32, low : Int32 ) : Int64 {
+		return new Int64(high, low);
+	}
+
+	public static inline function ofInt( x : Int ) : Int64 {
+		return new Int64((x >> 31).ofInt(),x.ofInt());
+	}
+
+	public static inline function ofInt32( x : Int32 ) : Int64 {
+		return new Int64(x.shr(31),x);
+	}
+
+	public static function toInt( x : Int64 ) : Int {
+		if( x.high.toInt() != 0 ) {
+			if( x.high.isNeg() )
+				return -toInt(neg(x));
+			throw "Overflow";
+		}
+		return x.low.toInt();
+	}
+
+	public static function getLow( x : Int64 ) : Int32 {
+		return x.low;
+	}
+
+	public static function getHigh( x : Int64 ) : Int32 {
+		return x.high;
+	}
+
+	public static function add( a : Int64, b : Int64 ) : Int64 {
+		var high = a.high.add(b.high);
+		var low = a.low.add(b.low);
+		if( low.ucompare(a.low) < 0 )
+			high = high.add(1.ofInt());
+		return new Int64(high, low);
+	}
+
+	public static function sub( a : Int64, b : Int64 ) : Int64 {
+		var high = a.high.sub(b.high);
+		var low = a.low.sub(b.low);
+		if( a.low.ucompare(b.low) < 0 )
+			high = high.sub(1.ofInt());
+		return new Int64(high, low);
+	}
+
+	public static function mul( a : Int64, b : Int64 ) : Int64 {
+		var mask = 0xFFFF.ofInt();
+		var al = a.low.and(mask), ah = a.low.ushr(16);
+		var bl = b.low.and(mask), bh = b.low.ushr(16);
+		var p00 = al.mul(bl);
+		var p10 = ah.mul(bl);
+		var p01 = al.mul(bh);
+		var p11 = ah.mul(bh);
+		var low = p00;
+		var high = p11.add(p01.ushr(16)).add(p10.ushr(16));
+		p01 = p01.shl(16); low = low.add(p01); if( low.ucompare(p01) < 0 ) high = high.add(1.ofInt());
+		p10 = p10.shl(16); low = low.add(p10); if( low.ucompare(p10) < 0 ) high = high.add(1.ofInt());
+		high = high.add(a.low.mul(b.high));
+		high = high.add(a.high.mul(b.low));
+		return new Int64(high, low);
+	}
+
+	static function divMod( modulus : Int64, divisor : Int64 ) {
+		var quotient = new Int64(0.ofInt(), 0.ofInt());
+		var mask = new Int64(0.ofInt(), 1.ofInt());
+		divisor = new Int64(divisor.high, divisor.low);
+		while( !divisor.high.isNeg() ) {
+			var cmp = ucompare(divisor, modulus);
+			divisor.high = divisor.high.shl(1).or(divisor.low.ushr(31));
+			divisor.low = divisor.low.shl(1);
+			mask.high = mask.high.shl(1).or(mask.low.ushr(31));
+			mask.low = mask.low.shl(1);
+			if( cmp >= 0 ) break;
+		}
+		while( !mask.low.or(mask.high).isZero() ) {
+			if( ucompare(modulus, divisor) >= 0 ) {
+				quotient.high = quotient.high.or(mask.high);
+				quotient.low = quotient.low.or(mask.low);
+				modulus = sub(modulus, divisor);
+			}
+			mask.low = mask.low.ushr(1).or(mask.high.shl(31));
+			mask.high = mask.high.ushr(1);
+
+			divisor.low = divisor.low.ushr(1).or(divisor.high.shl(31));
+			divisor.high = divisor.high.ushr(1);
+		}
+		return { quotient : quotient, modulus : modulus };
+	}
+
+	public static inline function div( a : Int64, b : Int64 ) : Int64 {
+		var sign = a.high.or(b.high).isNeg();
+		if( a.high.isNeg() ) a = neg(a);
+		if( b.high.isNeg() ) b = neg(b);
+		var q = divMod(a, b).quotient;
+		return sign ? neg(q) : q;
+	}
+
+	public static inline function mod( a : Int64, b : Int64 ) : Int64 {
+		var sign = a.high.or(b.high).isNeg();
+		if( a.high.isNeg() ) a = neg(a);
+		if( b.high.isNeg() ) b = neg(b);
+		var m = divMod(a, b).modulus;
+		return sign ? neg(m) : m;
+	}
+
+	public static inline function shl( a : Int64, b : Int ) : Int64 {
+		return if( b < 32 ) new Int64( a.high.shl(b).or(a.low.ushr(32 - b)), a.low.shl(b) ) else new Int64( a.low.shl(b - 32), 0.ofInt() );
+	}
+
+	public static inline function shr( a : Int64, b : Int ) : Int64 {
+		return if( b < 32 ) new Int64( a.high.shr(b), a.low.ushr(b).or(a.high.shl(32 - b)) ) else new Int64( a.high.shr(31), a.high.shr(b - 32) );
+	}
+
+	public static inline function ushr( a : Int64, b : Int ) : Int64 {
+		return if( b < 32 ) new Int64( a.high.ushr(b), a.low.ushr(b).or(a.high.shl(32 - b)) ) else new Int64( 0.ofInt(), a.high.ushr(b - 32) );
+	}
+
+	public static inline function and( a : Int64, b : Int64 ) : Int64 {
+		return new Int64( a.high.and(b.high), a.low.and(b.low) );
+	}
+
+	public static inline function or( a : Int64, b : Int64 ) : Int64 {
+		return new Int64( a.high.or(b.high), a.low.or(b.low) );
+	}
+
+	public static inline function xor( a : Int64, b : Int64 ) : Int64 {
+		return new Int64( a.high.xor(b.high), a.low.xor(b.low) );
+	}
+
+	public static inline function neg( a : Int64 ) : Int64 {
+		var high = Int32.complement(a.high);
+		var low = Int32.neg(a.low);
+		if( low.isZero() )
+			high = high.add(1.ofInt());
+		return new Int64(high,low);
+	}
+
+	public static inline function isNeg( a : Int64 ) : Bool {
+		return a.high.isNeg();
+	}
+
+	public static inline function isZero( a : Int64 ) : Bool {
+		return a.high.or(a.low).isZero();
+	}
+
+	public static inline function compare( a : Int64, b : Int64 ) : Int {
+		var v = Int32.compare(a.high,b.high);
+		return if( v != 0 ) v else Int32.ucompare(a.low, b.low);
+	}
+
+	/**
+		Compare two Int64 in unsigned mode.
+	**/
+	public static inline function ucompare( a : Int64, b : Int64 ) : Int {
+		var v = Int32.ucompare(a.high,b.high);
+		return if( v != 0 ) v else Int32.ucompare(a.low, b.low);
+	}
+
+}
+
+

+ 134 - 0
std/neko/_std/haxe/Int32.hx

@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe;
+
+@:core_api class Int32 {
+
+	public static inline function make( a : Int, b : Int ) : Int32 {
+		return add(shl(cast a,16),cast b);
+	}
+
+	public static inline function ofInt( x : Int ) : Int32 {
+		return untyped __i32__new(x);
+	}
+
+	public static inline function toInt( x : Int32 ) : Int {
+		return try untyped __i32__to_int(x) catch( e : Dynamic ) throw "Overflow"+x;
+	}
+
+	public static inline function toNativeInt( x : Int32 ) : Int {
+		return untyped (__i32__ushr(x,8) << 8) | __i32__and(x,0xFF);
+	}
+
+	public static inline function add( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__add(a,b);
+	}
+
+	public static inline function sub( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__sub(a,b);
+	}
+
+	public static inline function mul( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__mul(a,b);
+	}
+
+	public static inline function div( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__div(a,b);
+	}
+
+	public static inline function mod( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__mod(a,b);
+	}
+
+	public static inline function shl( a : Int32, b : Int ) : Int32 {
+		return untyped __i32__shl(a,b);
+	}
+
+	public static inline function shr( a : Int32, b : Int ) : Int32 {
+		return untyped __i32__shr(a,b);
+	}
+
+	public static inline function ushr( a : Int32, b : Int ) : Int32 {
+		return untyped __i32__ushr(a,b);
+	}
+
+	public static inline function and( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__and(a,b);
+	}
+
+	public static inline function or( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__or(a,b);
+	}
+
+	public static inline function xor( a : Int32, b : Int32 ) : Int32 {
+		return untyped __i32__xor(a,b);
+	}
+
+	public static inline function neg( a : Int32 ) : Int32 {
+		return untyped __i32__neg(a);
+	}
+
+	public static inline function isNeg( a : Int32 ) : Bool {
+		return untyped __i32__compare(a,0) < 0;
+	}
+
+	public static inline function isZero( a : Int32 ) : Bool {
+		return untyped __i32__compare(a,0) == 0;
+	}
+
+	public static inline function complement( a : Int32 ) : Int32 {
+		return untyped __i32__complement(a);
+	}
+
+	public static inline function compare( a : Int32, b : Int32 ) : Int {
+		return untyped __i32__compare(a,b);
+	}
+
+	public static function ucompare( a : Int32, b : Int32 ) : Int {
+		if( isNeg(a) )
+			return isNeg(b) ? compare(complement(b),complement(a)) : 1;
+		return isNeg(b) ? -1 : compare(a,b);
+	}
+
+	static function __init__() : Void untyped {
+		__i32__new = neko.Lib.load("std","int32_new",1);
+		__i32__to_int = neko.Lib.load("std","int32_to_int",1);
+		__i32__add = neko.Lib.load("std","int32_add",2);
+		__i32__sub = neko.Lib.load("std","int32_sub",2);
+		__i32__mul = neko.Lib.load("std","int32_mul",2);
+		__i32__div = neko.Lib.load("std","int32_div",2);
+		__i32__mod = neko.Lib.load("std","int32_mod",2);
+		__i32__shl = neko.Lib.load("std","int32_shl",2);
+		__i32__shr = neko.Lib.load("std","int32_shr",2);
+		__i32__ushr = neko.Lib.load("std","int32_ushr",2);
+		__i32__and = neko.Lib.load("std","int32_and",2);
+		__i32__or = neko.Lib.load("std","int32_or",2);
+		__i32__xor = neko.Lib.load("std","int32_xor",2);
+		__i32__neg = neko.Lib.load("std","int32_neg",1);
+		__i32__complement = neko.Lib.load("std","int32_complement",1);
+		__i32__compare = neko.Lib.load("std","int32_compare",2);
+	}
+
+}

+ 1 - 0
tests/unit/Test.hx

@@ -186,6 +186,7 @@ class Test #if swf_mark implements mt.Protect #end #if as3 implements haxe.Publi
 			new TestReflect(),
 			new TestBytes(),
 			new TestInt32(),
+			new TestInt64(),
 			new TestIO(),
 			new TestLocals(),
 			new TestSerialize(),

+ 26 - 2
tests/unit/TestInt32.hx

@@ -1,5 +1,6 @@
 package unit;
 import haxe.Int32;
+using haxe.Int32;
 
 class TestInt32 extends Test {
 
@@ -28,7 +29,8 @@ class TestInt32 extends Test {
 		eq( i(one), 1 );
 		eq( i(minone), -1 );
 		eq( i(i32(0x01020304)), 0x01020304 );
-		eq( i(Int32.make(0x0102,0x0304)), 0x01020304 );
+		eq( i(Int32.make(0x0102, 0x0304)), 0x01020304 );
+		eq( i(Int32.make(0x10102, 0x0304)), 0x01020304 );
 
 		// 31 bits overflow
 		exc( function() i(Int32.shl(one,30)) );
@@ -46,6 +48,16 @@ class TestInt32 extends Test {
 		eq( Int32.compare(minone,zero), -1 );
 		eq( Int32.compare(zero,minone), 1 );
 
+		eq( Int32.ucompare(one,one), 0 );
+		eq( Int32.ucompare(one,zero), 1 );
+		eq( Int32.ucompare(zero,one), -1 );
+		eq( Int32.ucompare(minone,minone), 0 );
+		eq( Int32.ucompare(minone,zero), 1 );
+		eq( Int32.ucompare(zero,minone), -1 );
+		eq( Int32.ucompare((-1).ofInt(),(-2).ofInt()), 1 );
+		eq( Int32.ucompare((-2).ofInt(),(-1).ofInt()), -1 );
+
+
 		eq( i(Int32.add(one,one)), 2 );
 		eq( i(Int32.sub(minone,one)), -2 );
 		eq( i(Int32.mul(i32(5),i32(100))), 500 );
@@ -76,7 +88,19 @@ class TestInt32 extends Test {
 		eq( i(Int32.xor(i32(0xFE08BE39),i32(0xCBCDEF99))), 0x35C551A0 );
 		eq( i(Int32.neg(one)), -1 );
 		eq( i(Int32.complement(i32(55))), -56 );
-		eq( i(Int32.complement(i32(-0x10000))), 0xFFFF );
+		eq( i(Int32.complement(i32( -0x10000))), 0xFFFF );
+
+		// check overflows
+		eq( i(i32((1 << 29) * 255)), 0xE0000000 );
+
+		eq( 0x050BCDEF.ofInt().shl(8).ushr(8).toInt(), 0x0BCDEF );
+
+		eq( 0x050BCDEF.ofInt().shl(8).div(256.ofInt()).toInt(), 0x0BCDEF );
+
+		eq( 7.ofInt().div(3.ofInt()).mul(3.ofInt()).toInt(), 6 );
+
+		eq( 0x050BCDEF.ofInt().mul(256.ofInt()).mod(0xFF.ofInt()).toInt(), 200 );
+
 	}
 
 }

+ 23 - 0
tests/unit/TestInt64.hx

@@ -0,0 +1,23 @@
+package unit;
+using haxe.Int64;
+
+class TestInt64 extends Test {
+
+	inline function eq32( i : haxe.Int32, a : Int, b : Int, ?pos : haxe.PosInfos ) {
+		var i2 = haxe.Int32.make(a, b);
+		if( haxe.Int32.compare(i, i2) != 0 )
+			Test.report(Std.string(i)+" should be "+Std.string(i2),pos);
+	}
+	
+	public function test() {
+		eq( 1.ofInt().toInt(), 1 );
+		eq( ( -1).ofInt().toInt(), -1 );
+		eq( Std.string(156.ofInt()), "156" );
+		
+		var p40 = (1 << 20).ofInt().shl(20);
+		eq32( p40.getLow(), 0, 0 );
+		eq32( p40.getHigh(), 0, 256 );
+		eq( Std.string(p40), "1099511627776" );
+	}
+
+}