-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.hx
More file actions
180 lines (141 loc) · 4.02 KB
/
Math.hx
File metadata and controls
180 lines (141 loc) · 4.02 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package;
extern class Math {
@:nativeFunctionCode("3.141592653589793")
static var PI(default, null):Float;
@:nativeFunctionCode("(0.0 / 0.0)")
static var NaN(default, null):Float;
@:nativeFunctionCode("(1.0 / 0.0)")
static var POSITIVE_INFINITY(default, null):Float;
@:nativeFunctionCode("(-1.0 / 0.0)")
static var NEGATIVE_INFINITY(default, null):Float;
@:nativeFunctionCode("Abs({arg0})")
static function abs(v:Float):Float;
@:nativeFunctionCode("Sin({arg0})")
static function sin(v:Float):Float;
@:nativeFunctionCode("Cos({arg0})")
static function cos(v:Float):Float;
@:nativeFunctionCode("Tan({arg0})")
static function tan(v:Float):Float;
@:nativeFunctionCode("Exp({arg0})")
static function exp(v:Float):Float;
@:nativeFunctionCode("Log({arg0})")
static function log(v:Float):Float;
@:nativeFunctionCode("Sqr({arg0})")
static function sqrt(v:Float):Float;
@:nativeFunctionCode("Atn({arg0})")
static function atan(v:Float):Float;
@:nativeFunctionCode("Rnd(0)")
static function random():Float;
@:nativeFunctionCode("({arg0} ^ {arg1})")
static function pow(v:Float, exp:Float):Float;
@:nativeFunctionCode("__Math_asin__({arg0})")
static function asin(v:Float):Float;
@:nativeFunctionCode("__Math_acos__({arg0})")
static function acos(v:Float):Float;
@:nativeFunctionCode("__Math_atan2__({arg0}, {arg1})")
static function atan2(y:Float, x:Float):Float;
@:nativeFunctionCode("__Math_ceil__({arg0})")
static function ceil(v:Float):Int;
@:nativeFunctionCode("__Math_floor__({arg0})")
static function floor(v:Float):Int;
@:nativeFunctionCode("__Math_round__({arg0})")
static function round(v:Float):Int;
@:nativeFunctionCode("__Math_fceil__({arg0})")
static function fceil(v:Float):Float;
@:nativeFunctionCode("__Math_ffloor__({arg0})")
static function ffloor(v:Float):Float;
@:nativeFunctionCode("__Math_fround__({arg0})")
static function fround(v:Float):Float;
@:nativeFunctionCode("__Math_max__({arg0}, {arg1})")
static function max(a:Float, b:Float):Float;
@:nativeFunctionCode("__Math_min__({arg0}, {arg1})")
static function min(a:Float, b:Float):Float;
@:runtime public inline static function isNaN(f:Float):Bool {
return f != f;
}
@:nativeFunctionCode("__Math_isFinite__({arg0})")
static function isFinite(f:Float):Bool;
}
@:keep @:brs_global function __Math_isFinite__(f:Float) {
if (f != f)
return false;
if (f - f != 0.0)
return false;
return true;
}
@:keep @:brs_global function __Math_floor__(v:Float) {
final i = Std.int(v);
if (v < i)
return i - 1;
return i;
}
@:keep @:brs_global function __Math_ceil__(v:Float) {
final i = Std.int(v);
if (v > i)
return i + 1;
return i;
}
@:keep @:brs_global function __Math_round__(v:Float) {
final v2 = v + 0.5;
final i = Std.int(v2);
if (v2 < i)
return i - 1;
return i;
}
@:keep @:brs_global function __Math_ffloor__(v:Float) {
final i = Std.int(v);
if (v < i)
return i - 1.0;
return i + 0.0;
}
@:keep @:brs_global function __Math_fceil__(v:Float) {
final i = Std.int(v);
if (v > i)
return i + 1.0;
return i + 0.0;
}
@:keep @:brs_global function __Math_fround__(v:Float) {
final v2 = v + 0.5;
final i = Std.int(v2);
if (v2 < i)
return i - 1.0;
return i + 0.0;
}
@:keep @:brs_global function __Math_max__(a:Float, b:Float) {
if (a >= b)
return a;
return b;
}
@:keep @:brs_global function __Math_min__(a:Float, b:Float) {
if (a <= b)
return a;
return b;
}
@:keep @:brs_global function __Math_asin__(v:Float) {
if (v >= 1.0)
return Math.PI / 2.0;
if (v <= -1.0)
return -(Math.PI / 2.0);
return Math.atan(v / Math.sqrt(1.0 - v * v));
}
@:keep @:brs_global function __Math_acos__(v:Float) {
if (v >= 1.0)
return 0.0;
if (v <= -1.0)
return Math.PI;
return Math.PI / 2.0 - Math.atan(v / Math.sqrt(1.0 - v * v));
}
@:keep @:brs_global function __Math_atan2__(y:Float, x:Float) {
if (x > 0.0)
return Math.atan(y / x);
if (x < 0.0) {
if (y >= 0.0)
return Math.atan(y / x) + Math.PI;
return Math.atan(y / x) - Math.PI;
}
if (y > 0.0)
return Math.PI / 2.0;
if (y < 0.0)
return -(Math.PI / 2.0);
return 0.0;
}