Skip to content

Commit 99b7196

Browse files
authored
Improve math tests by using Object.is for -0.0 checks (#2504)
1 parent e5fb10b commit 99b7196

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

tests/compiler/std/math.debug.wat

+35-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
(type $f64_i32_f64_f64_i32_=>_i32 (func (param f64 i32 f64 f64 i32) (result i32)))
2020
(type $f32_i32_f32_f32_i32_=>_i32 (func (param f32 i32 f32 f32 i32) (result i32)))
2121
(type $f64_i64_=>_i32 (func (param f64 i64) (result i32)))
22+
(type $f64_f64_=>_i32 (func (param f64 f64) (result i32)))
2223
(type $i64_=>_i64 (func (param i64) (result i64)))
2324
(type $i32_=>_i32 (func (param i32) (result i32)))
2425
(type $i64_=>_none (func (param i64)))
@@ -10567,6 +10568,28 @@
1056710568
i32.const 0
1056810569
end
1056910570
)
10571+
(func $~lib/object/Object.is<f64> (param $x f64) (param $y f64) (result i32)
10572+
i32.const 1
10573+
drop
10574+
i32.const 8
10575+
i32.const 8
10576+
i32.eq
10577+
drop
10578+
local.get $x
10579+
local.get $x
10580+
f64.ne
10581+
local.get $y
10582+
local.get $y
10583+
f64.ne
10584+
i32.and
10585+
local.get $x
10586+
i64.reinterpret_f64
10587+
local.get $y
10588+
i64.reinterpret_f64
10589+
i64.eq
10590+
i32.or
10591+
return
10592+
)
1057010593
(func $~lib/math/NativeMathf.pow (param $x f32) (param $y f32) (result f32)
1057110594
(local $var$2 f32)
1057210595
(local $var$3 f32)
@@ -43070,7 +43093,9 @@
4307043093
f64.const 1
4307143094
call $~lib/math/NativeMath.pow
4307243095
f64.const 0
43073-
f64.eq
43096+
call $~lib/object/Object.is<f64>
43097+
i32.const 0
43098+
i32.ne
4307443099
i32.eqz
4307543100
if
4307643101
i32.const 0
@@ -43084,7 +43109,9 @@
4308443109
f64.const 1
4308543110
call $~lib/math/NativeMath.pow
4308643111
f64.const -0
43087-
f64.eq
43112+
call $~lib/object/Object.is<f64>
43113+
i32.const 0
43114+
i32.ne
4308843115
i32.eqz
4308943116
if
4309043117
i32.const 0
@@ -43228,7 +43255,9 @@
4322843255
f64.const -1
4322943256
call $~lib/math/NativeMath.pow
4323043257
f64.const 0
43231-
f64.eq
43258+
call $~lib/object/Object.is<f64>
43259+
i32.const 0
43260+
i32.ne
4323243261
i32.eqz
4323343262
if
4323443263
i32.const 0
@@ -43243,7 +43272,9 @@
4324343272
f64.const -1
4324443273
call $~lib/math/NativeMath.pow
4324543274
f64.const -0
43246-
f64.eq
43275+
call $~lib/object/Object.is<f64>
43276+
i32.const 0
43277+
i32.ne
4324743278
i32.eqz
4324843279
if
4324943280
i32.const 0

tests/compiler/std/math.release.wat

+12-8
Original file line numberDiff line numberDiff line change
@@ -40016,8 +40016,9 @@
4001640016
f64.const 0
4001740017
f64.const 1
4001840018
call $~lib/math/NativeMath.pow
40019-
f64.const 0
40020-
f64.ne
40019+
i64.reinterpret_f64
40020+
i64.const 0
40021+
i64.ne
4002140022
if
4002240023
i32.const 0
4002340024
i32.const 1056
@@ -40029,8 +40030,9 @@
4002940030
f64.const -0
4003040031
f64.const 1
4003140032
call $~lib/math/NativeMath.pow
40032-
f64.const -0
40033-
f64.ne
40033+
i64.reinterpret_f64
40034+
i64.const -9223372036854775808
40035+
i64.ne
4003440036
if
4003540037
i32.const 0
4003640038
i32.const 1056
@@ -40160,8 +40162,9 @@
4016040162
f64.const inf
4016140163
f64.const -1
4016240164
call $~lib/math/NativeMath.pow
40163-
f64.const 0
40164-
f64.ne
40165+
i64.reinterpret_f64
40166+
i64.const 0
40167+
i64.ne
4016540168
if
4016640169
i32.const 0
4016740170
i32.const 1056
@@ -40173,8 +40176,9 @@
4017340176
f64.const -inf
4017440177
f64.const -1
4017540178
call $~lib/math/NativeMath.pow
40176-
f64.const -0
40177-
f64.ne
40179+
i64.reinterpret_f64
40180+
i64.const -9223372036854775808
40181+
i64.ne
4017840182
if
4017940183
i32.const 0
4018040184
i32.const 1056

tests/compiler/std/math.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2695,8 +2695,8 @@ assert(NativeMath.pow(+Infinity, 0.0) == 1.0);
26952695
assert(NativeMath.pow(-Infinity, 0.0) == 1.0);
26962696
assert(NativeMath.pow(NaN, 0.0) == 1.0);
26972697

2698-
assert(NativeMath.pow(+0.0,+1.0) == +0.0);
2699-
assert(NativeMath.pow(-0.0,+1.0) == -0.0);
2698+
assert(Object.is(NativeMath.pow(+0.0,+1.0), +0.0));
2699+
assert(Object.is(NativeMath.pow(-0.0,+1.0), -0.0));
27002700
assert(NativeMath.pow(-1.0, 1.0) == -1.0);
27012701
assert(NativeMath.pow(+Infinity, 1.0) == +Infinity);
27022702
assert(NativeMath.pow(-Infinity, 1.0) == -Infinity);
@@ -2707,8 +2707,8 @@ assert(NativeMath.pow(-0.0,-1.0) == -Infinity);
27072707
assert(NativeMath.pow(-1.0,-1.0) == -1.0);
27082708
assert(NativeMath.pow( 0.5,-1.0) == +2.0);
27092709
assert(NativeMath.pow( 1.0,-1.0) == +1.0);
2710-
assert(NativeMath.pow(+Infinity,-1.0) == +0.0);
2711-
assert(NativeMath.pow(-Infinity,-1.0) == -0.0);
2710+
assert(Object.is(NativeMath.pow(+Infinity,-1.0), +0.0));
2711+
assert(Object.is(NativeMath.pow(-Infinity,-1.0), -0.0));
27122712
assert(isNaN(NativeMath.pow(NaN,-1.0)));
27132713

27142714
assert(NativeMath.pow(+0.0, 2.0) == +0.0);

0 commit comments

Comments
 (0)