-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInt32Math.hx
More file actions
164 lines (126 loc) · 4.18 KB
/
Int32Math.hx
File metadata and controls
164 lines (126 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package deep.math;
import haxe.Int32;
/**
* ...
* @author deep <system.grand@gmail.com>
*/
class Int32Math
{
@op("+", true) inline static public var add = Int32.add;
@op("+", true) inline static public function addInt(a:Int32, b:Int):Int32
{
return Int32.add(a, Int32.ofInt(b));
}
@op("-", true) inline static public var sub = Int32.sub;
@op("-", false) inline static public function subInt(a:Int32, b:Int):Int32
{
return Int32.sub(a, Int32.ofInt(b));
}
@op("*", true) inline static public var mult = Int32.mul;
@op("*", true) inline static public function multInt(a:Int32, b:Int):Int32
{
return Int32.mul(a, Int32.ofInt(b));
}
@op("/", true) inline static public var div = Int32.div;
@op("/", false) inline static public function divInt(a:Int32, b:Int):Int32
{
return Int32.div(a, Int32.ofInt(b));
}
@op("%", true) inline static public var mod = Int32.mod;
@op("%", false) inline static public function modInt(a:Int32, b:Int):Int32
{
return Int32.mod(a, Int32.ofInt(b));
}
@op("+=", true) inline static public var iadd = Int32.add;
@op("+=", false) inline static public function iaddInt(a:Int32, b:Int):Int32
{
return Int32.add(a, Int32.ofInt(b));
}
@op("-=", true) inline static public var isub = Int32.sub;
@op("-=", false) inline static public function isubInt(a:Int32, b:Int):Int32
{
return Int32.sub(a, Int32.ofInt(b));
}
@op("*=", true) inline static public var imult = Int32.mul;
@op("*=", false) inline static public function imultInt(a:Int32, b:Int):Int32
{
return Int32.mul(a, Int32.ofInt(b));
}
@op("/=", true) inline static public var idiv = Int32.div;
@op("/=", false) inline static public function idivInt(a:Int32, b:Int):Int32
{
return Int32.div(a, Int32.ofInt(b));
}
@op("%=", true) inline static public var imod = Int32.mod;
@op("%=", false) inline static public function imodInt(a:Int32, b:Int):Int32
{
return Int32.mod(a, Int32.ofInt(b));
}
@op("<<", true) inline static public var shl = Int32.shl;
@op("<<=", true) inline static public var ishl = Int32.shl;
@op(">>", true) inline static public var shr = Int32.shr;
@op(">>=", true) inline static public var ishr = Int32.shr;
@op(">>>", true) inline static public var ushr = Int32.ushr;
@op(">>>=", true) inline static public var iushr = Int32.ushr;
@op("&", true) inline static public var and = Int32.and;
@op("&=", true) inline static public var iand = Int32.and;
@op("|", true) inline static public var or = Int32.or;
@op("|=", true) inline static public var ior = Int32.or;
@op("^", true) inline static public var xor = Int32.xor;
@op("^=", true) inline static public var ixor = Int32.xor;
@op("-x") inline static public var neg = Int32.neg;
@op("++x", false) inline static public function inc(a:Int32):Int32
{
return Int32.add(a, Int32.ofInt(1));
}
@op("x++", false) inline static public function pinc(a:Int32):Int32
{
return Int32.add(a, Int32.ofInt(1));
}
@op("--x", false) inline static public function dec(a:Int32):Int32
{
return Int32.sub(a, Int32.ofInt(1));
}
@op("x--", false) inline static public function pdec(a:Int32):Int32
{
return Int32.sub(a, Int32.ofInt(1));
}
@op(">", false) inline static public function gt(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) > 0;
}
@op(">=", false) inline static public function gte(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) >= 0;
}
@op("<", false) inline static public function lt(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) < 0;
}
@op("<=", false) inline static public function lte(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) <= 0;
}
@op("==", true) inline static public function eq(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) == 0;
}
@op("==", true) inline public static function eqInt(a:Int32, b:Int):Bool
{
return Int32.compare(a, Int32.ofInt(b)) == 0;
}
@op("!=", true) inline static public function neq(a:Int32, b:Int32):Bool
{
return Int32.compare(a, b) != 0;
}
@op("!=", true) inline public static function neqInt(a:Int32, b:Int):Bool
{
return Int32.compare(a, Int32.ofInt(b)) != 0;
}
inline static public function abs(a:Int32):Int32
{
if (Int32.isNeg(a))
return Int32.neg(a);
return a;
}
}