Skip to content

Commit bbf1e9e

Browse files
jarca0123SuchAFuriousDeath
authored andcommitted
avm2: Implement missing Number static methods
Add static methods to Number class that mirror Math methods: - Trigonometric: sin, cos, tan, asin, acos, atan, atan2 - Arithmetic: abs, ceil, floor, round, sqrt, exp, log, pow - Comparison: max, min - Utility: random These methods delegate to their Math counterparts and enable previously failing avmplus tests. Co-authored-by: Tomáš Procházka <[email protected]>
1 parent 9a1a1fd commit bbf1e9e

File tree

14 files changed

+93
-12
lines changed

14 files changed

+93
-12
lines changed

core/src/avm2/globals/Number.as

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,80 @@ package {
3636
[API("680")]
3737
public static const LOG10E:Number = 0.4342944819032518;
3838

39+
[API("680")]
40+
[Ruffle(FastCall)]
41+
public static native function abs(x:Number):Number;
42+
43+
[API("680")]
44+
[Ruffle(FastCall)]
45+
public static native function acos(x:Number):Number;
46+
47+
[API("680")]
48+
[Ruffle(FastCall)]
49+
public static native function asin(x:Number):Number;
50+
51+
[API("680")]
52+
[Ruffle(FastCall)]
53+
public static native function atan(x:Number):Number;
54+
55+
[API("680")]
56+
[Ruffle(FastCall)]
57+
public static native function atan2(y:Number, x:Number):Number;
58+
59+
[API("680")]
60+
[Ruffle(FastCall)]
61+
public static native function ceil(x:Number):Number;
62+
63+
[API("680")]
64+
[Ruffle(FastCall)]
65+
public static native function cos(x:Number):Number;
66+
67+
[API("680")]
68+
[Ruffle(FastCall)]
69+
public static native function exp(x:Number):Number;
70+
71+
[API("680")]
72+
[Ruffle(FastCall)]
73+
public static native function floor(x:Number):Number;
74+
75+
[API("680")]
76+
[Ruffle(FastCall)]
77+
public static native function log(x:Number):Number;
78+
79+
// NOTE: See the the comment in Math.as for why max and min are marked as FastCall
80+
81+
[API("680")]
82+
[Ruffle(FastCall)]
83+
public static native function max(x:Number = NEGATIVE_INFINITY, y:Number = NEGATIVE_INFINITY, ...rest):Number;
84+
85+
[API("680")]
86+
[Ruffle(FastCall)]
87+
public static native function min(x:Number = POSITIVE_INFINITY, y:Number = POSITIVE_INFINITY, ...rest):Number;
88+
89+
[API("680")]
90+
[Ruffle(FastCall)]
91+
public static native function pow(x:Number, y:Number):Number;
92+
93+
[API("680")]
94+
[Ruffle(FastCall)]
95+
public static native function random():Number;
96+
97+
[API("680")]
98+
[Ruffle(FastCall)]
99+
public static native function round(x:Number):Number;
100+
101+
[API("680")]
102+
[Ruffle(FastCall)]
103+
public static native function sin(x:Number):Number;
104+
105+
[API("680")]
106+
[Ruffle(FastCall)]
107+
public static native function sqrt(x:Number):Number;
108+
109+
[API("680")]
110+
[Ruffle(FastCall)]
111+
public static native function tan(x:Number):Number;
112+
39113
{
40114
prototype.toExponential = function(digits:* = 0):String {
41115
var self:Number = this;

core/src/avm2/globals/number.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ pub fn number_constructor<'gc>(
1919
Ok(number_value.into())
2020
}
2121

22+
macro_rules! define_math_functions {
23+
($($name:ident),* $(,)?) => {
24+
$(
25+
pub fn $name<'gc>(
26+
activation: &mut Activation<'_, 'gc>,
27+
this: Value<'gc>,
28+
args: &[Value<'gc>],
29+
) -> Result<Value<'gc>, Error<'gc>> {
30+
crate::avm2::globals::math::$name(activation, this, args)
31+
}
32+
)*
33+
};
34+
}
35+
36+
define_math_functions!(
37+
abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin,
38+
sqrt, tan
39+
);
40+
2241
pub fn call_handler<'gc>(
2342
activation: &mut Activation<'_, 'gc>,
2443
_this: Value<'gc>,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true

0 commit comments

Comments
 (0)