Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 47 additions & 105 deletions std/haxe/Int32.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,155 +76,97 @@ 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<T:Int>(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<T:Int>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(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<T:Float>(a:T, b:Int32):Bool
return a >= (b : Float);

@:op(~A) private static inline function complement(a:Int32):Int32
return Int32Native.complement(a);

@: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.
**/
Expand Down
9 changes: 9 additions & 0 deletions std/haxe/numeric/Int32Direct.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
9 changes: 9 additions & 0 deletions std/haxe/numeric/Int32Native.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading