diff --git a/std/haxe/Int32.hx b/std/haxe/Int32.hx index 1f08d229c43..04e42d3da79 100644 --- a/std/haxe/Int32.hx +++ b/std/haxe/Int32.hx @@ -76,103 +76,65 @@ abstract Int32(Int32Native) from Int to Int { @:op(A + B) private static inline function add(a:Int32, b:Int32):Int32 return Int32Native.add(a, b); - @:op(A + B) @:commutative private static inline function addInt(a:Int32, b:Int):Int32 - return Int32Native.add(a, b); - - @:op(A + B) @:commutative private static function addFloat(a:Int32, b:Float):Float; - @:op(A - B) private static inline function sub(a:Int32, b:Int32):Int32 return Int32Native.sub(a, b); - @:op(A - B) private static inline function subInt(a:Int32, b:Int):Int32 - return Int32Native.sub(a, b); - - @:op(A - B) private static inline function intSub(a:Int, b:Int32):Int32 - return Int32Native.sub(a, b); - - @:op(A - B) private static function subFloat(a:Int32, b:Float):Float; - - @:op(A - B) private static function floatSub(a:Float, b:Int32):Float; - @:op(A * B) private static inline function mul(a:Int32, b:Int32):Int32 return Int32Native.mul(a, b); - @:op(A * B) @:commutative private static inline function mulInt(a:Int32, b:Int):Int32 - return Int32Native.mul(a, b); - - @:op(A * B) @:commutative private static function mulFloat(a:Int32, b:Float):Float; - - @:op(A / B) private static function div(a:Int32, b:Int32):Float; - - @:op(A / B) private static function divInt(a:Int32, b:Int):Float; - - @:op(A / B) private static function intDiv(a:Int, b:Int32):Float; - - @:op(A / B) private static function divFloat(a:Int32, b:Float):Float; - - @:op(A / B) private static function floatDiv(a:Float, b:Int32):Float; - - @:op(A % B) private static function mod(a:Int32, b:Int32):Int32; - - @:op(A % B) private static function modInt(a:Int32, b:Int):Int; - - @:op(A % B) private static function intMod(a:Int, b:Int32):Int; - - @:op(A % B) private static function modFloat(a:Int32, b:Float):Float; - - @:op(A % B) private static function floatMod(a:Float, b:Int32):Float; - - @:op(A == B) private static function eq(a:Int32, b:Int32):Bool; - - @:op(A == B) @:commutative private static function eqInt(a:Int32, b:Int):Bool; - - @:op(A == B) @:commutative private static function eqFloat(a:Int32, b:Float):Bool; + @:op(A / B) private static inline function div(a:Int32, b:Int32):Float + return (a : Int) / (b : Int); - @:op(A != B) private static function neq(a:Int32, b:Int32):Bool; + @:op(A % B) private static inline function mod(a:Int32, b:Int32):Int32 + return Int32Native.mod(a, b); - @:op(A != B) @:commutative private static function neqInt(a:Int32, b:Int):Bool; + @:op(A == B) @:commutative private static inline function equalsInt(a:Int32, b:T):Bool + return (a : Int) == b; - @:op(A != B) @:commutative private static function neqFloat(a:Int32, b:Float):Bool; + @:op(A != B) @:commutative private static inline function notEqualsInt(a:Int32, b:T):Bool + return (a : Int) != b; - @:op(A < B) private static function lt(a:Int32, b:Int32):Bool; + @:op(A == B) @:commutative private static inline function equalsFloat(a:Int32, b:T):Bool + return (a : Float) == b; - @:op(A < B) private static function ltInt(a:Int32, b:Int):Bool; + @:op(A != B) @:commutative private static inline function notEqualsFloat(a:Int32, b:T):Bool + return (a : Float) != b; - @:op(A < B) private static function intLt(a:Int, b:Int32):Bool; + @:op(A < B) private static inline function lt(a:Int32, b:Int32):Bool + return compare(a, b) < 0; - @:op(A < B) private static function ltFloat(a:Int32, b:Float):Bool; + @:op(A <= B) private static inline function lte(a:Int32, b:Int32):Bool + return compare(a, b) <= 0; - @:op(A < B) private static function floatLt(a:Float, b:Int32):Bool; + @:op(A > B) private static inline function gt(a:Int32, b:Int32):Bool + return compare(a, b) > 0; - @:op(A <= B) private static function lte(a:Int32, b:Int32):Bool; + @:op(A >= B) private static inline function gte(a:Int32, b:Int32):Bool + return compare(a, b) >= 0; - @:op(A <= B) private static function lteInt(a:Int32, b:Int):Bool; + @:op(A < B) private static inline function ltFloat(a:Int32, b:T):Bool + return (a : Float) < b; - @:op(A <= B) private static function intLte(a:Int, b:Int32):Bool; + @:op(A < B) private static inline function floatLt(a:T, b:Int32):Bool + return a < (b : Float); - @:op(A <= B) private static function lteFloat(a:Int32, b:Float):Bool; + @:op(A <= B) private static inline function lteFloat(a:Int32, b:T):Bool + return (a : Float) <= b; - @:op(A <= B) private static function floatLte(a:Float, b:Int32):Bool; + @:op(A <= B) private static inline function floatLte(a:T, b:Int32):Bool + return a <= (b : Float); - @:op(A > B) private static function gt(a:Int32, b:Int32):Bool; + @:op(A > B) private static inline function gtFloat(a:Int32, b:T):Bool + return (a : Float) > b; - @:op(A > B) private static function gtInt(a:Int32, b:Int):Bool; + @:op(A > B) private static inline function floatGt(a:T, b:Int32):Bool + return a > (b : Float); - @:op(A > B) private static function intGt(a:Int, b:Int32):Bool; + @:op(A >= B) private static inline function gteFloat(a:Int32, b:T):Bool + return (a : Float) >= b; - @:op(A > B) private static function gtFloat(a:Int32, b:Float):Bool; - - @:op(A > B) private static function floatGt(a:Float, b:Int32):Bool; - - @:op(A >= B) private static function gte(a:Int32, b:Int32):Bool; - - @:op(A >= B) private static function gteInt(a:Int32, b:Int):Bool; - - @:op(A >= B) private static function intGte(a:Int, b:Int32):Bool; - - @:op(A >= B) private static function gteFloat(a:Int32, b:Float):Bool; - - @:op(A >= B) private static function floatGte(a:Float, b:Int32):Bool; + @:op(A >= B) private static inline function floatGte(a:T, b:Int32):Bool + return a >= (b : Float); @:op(~A) private static inline function complement(a:Int32):Int32 return Int32Native.complement(a); @@ -180,51 +142,31 @@ abstract Int32(Int32Native) from Int to Int { @:op(A & B) private static inline function and(a:Int32, b:Int32):Int32 return Int32Native.and(a, b); - @:op(A & B) @:commutative private static inline function andInt(a:Int32, b:Int):Int32 - return Int32Native.and(a, b); - @:op(A | B) private static inline function or(a:Int32, b:Int32):Int32 return Int32Native.or(a, b); - @:op(A | B) @:commutative private static inline function orInt(a:Int32, b:Int):Int32 - return Int32Native.or(a, b); - @:op(A ^ B) private static inline function xor(a:Int32, b:Int32):Int32 return Int32Native.xor(a, b); - @:op(A ^ B) @:commutative private static inline function xorInt(a:Int32, b:Int):Int32 - return Int32Native.xor(a, b); - - @:op(A >> B) private static inline function shr(a:Int32, b:Int32):Int32 - return Int32Native.shr(a, (b : Int)); + @:op(A << B) private static inline function shl(a:Int32, b:Int):Int32 + return Int32Native.shl(a, b); - @:op(A >> B) private static inline function shrInt(a:Int32, b:Int):Int32 + @:op(A >> B) private static inline function shr(a:Int32, b:Int):Int32 return Int32Native.shr(a, b); - @:op(A >> B) private static inline function intShr(a:Int, b:Int32):Int32 - return Int32Native.shr(a, (b : Int)); - - @:op(A >>> B) private static inline function ushr(a:Int32, b:Int32):Int32 - return Int32Native.ushr(a, (b : Int)); - - @:op(A >>> B) private static inline function ushrInt(a:Int32, b:Int):Int32 + @:op(A >>> B) private static inline function ushr(a:Int32, b:Int):Int32 return Int32Native.ushr(a, b); - @:op(A >>> B) private static inline function intUshr(a:Int, b:Int32):Int32 - return Int32Native.ushr(a, (b : Int)); - - @:op(A << B) private static inline function shl(a:Int32, b:Int32):Int32 - return Int32Native.shl(a, (b : Int)); - - @:op(A << B) private static inline function shlInt(a:Int32, b:Int):Int32 - return Int32Native.shl(a, b); - - @:op(A << B) private static inline function intShl(a:Int, b:Int32):Int32 - return Int32Native.shl(a, (b : Int)); - @:to private inline function toFloat():Float return (this : Int); + /** + Compare `a` and `b` in signed mode. + Returns a negative value if `a < b`, positive if `a > b`, or 0 if `a == b`. + **/ + public static inline function compare(a:Int32, b:Int32):Int + return Int32Native.compare(a, b); + /** Compare `a` and `b` in unsigned mode. **/ diff --git a/std/haxe/numeric/Int32Direct.hx b/std/haxe/numeric/Int32Direct.hx index c8d07cd6017..81c482a6f24 100644 --- a/std/haxe/numeric/Int32Direct.hx +++ b/std/haxe/numeric/Int32Direct.hx @@ -67,6 +67,12 @@ abstract Int32Direct(Int) from Int to Int { public static inline function ushr(a:Int32Direct, b:Int):Int32Direct return cast((a : Int) >>> b); + public static inline function compare(a:Int32Direct, b:Int32Direct):Int { + var av:Int = a; + var bv:Int = b; + return av < bv ? -1 : (av > bv ? 1 : 0); + } + public static function ucompare(a:Int32Direct, b:Int32Direct):Int { if ((a : Int) < 0) return (b : Int) < 0 ? (~(b : Int) - ~(a : Int)) : 1; @@ -76,6 +82,9 @@ abstract Int32Direct(Int) from Int to Int { public inline function toFloat():Float return this; + public static inline function mod(a:Int32Direct, b:Int32Direct):Int32Direct + return cast((a : Int) % (b : Int)); + public static inline function clamp(x:Int):Int32Direct return cast x; } diff --git a/std/haxe/numeric/Int32Native.hx b/std/haxe/numeric/Int32Native.hx index 189df0f0cbf..3c5e4f6f35f 100644 --- a/std/haxe/numeric/Int32Native.hx +++ b/std/haxe/numeric/Int32Native.hx @@ -101,12 +101,21 @@ private abstract Int32NativeImpl(Int) from Int to Int { public static inline function ushr(a:Int32Native, b:Int):Int32Native return cast((a : Int) >>> b); + public static inline function compare(a:Int32Native, b:Int32Native):Int { + var av:Int = a; + var bv:Int = b; + return av < bv ? -1 : (av > bv ? 1 : 0); + } + public static function ucompare(a:Int32Native, b:Int32Native):Int { if ((a : Int) < 0) return (b : Int) < 0 ? (~(b : Int) - ~(a : Int)) : 1; return (b : Int) < 0 ? -1 : ((a : Int) - (b : Int)); } + public static inline function mod(a:Int32Native, b:Int32Native):Int32Native + return cast((a : Int) % (b : Int)); + public inline function toFloat():Float return this;