Skip to content

Improve math tests by using Object.is for -0.0 checks #2504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2022
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
39 changes: 35 additions & 4 deletions tests/compiler/std/math.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
(type $f64_i32_f64_f64_i32_=>_i32 (func (param f64 i32 f64 f64 i32) (result i32)))
(type $f32_i32_f32_f32_i32_=>_i32 (func (param f32 i32 f32 f32 i32) (result i32)))
(type $f64_i64_=>_i32 (func (param f64 i64) (result i32)))
(type $f64_f64_=>_i32 (func (param f64 f64) (result i32)))
(type $i64_=>_i64 (func (param i64) (result i64)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i64_=>_none (func (param i64)))
Expand Down Expand Up @@ -10567,6 +10568,28 @@
i32.const 0
end
)
(func $~lib/object/Object.is<f64> (param $x f64) (param $y f64) (result i32)
i32.const 1
drop
i32.const 8
i32.const 8
i32.eq
drop
local.get $x
local.get $x
f64.ne
local.get $y
local.get $y
f64.ne
i32.and
local.get $x
i64.reinterpret_f64
local.get $y
i64.reinterpret_f64
i64.eq
i32.or
return
)
(func $~lib/math/NativeMathf.pow (param $x f32) (param $y f32) (result f32)
(local $var$2 f32)
(local $var$3 f32)
Expand Down Expand Up @@ -43070,7 +43093,9 @@
f64.const 1
call $~lib/math/NativeMath.pow
f64.const 0
f64.eq
call $~lib/object/Object.is<f64>
i32.const 0
i32.ne
i32.eqz
if
i32.const 0
Expand All @@ -43084,7 +43109,9 @@
f64.const 1
call $~lib/math/NativeMath.pow
f64.const -0
f64.eq
call $~lib/object/Object.is<f64>
i32.const 0
i32.ne
i32.eqz
if
i32.const 0
Expand Down Expand Up @@ -43228,7 +43255,9 @@
f64.const -1
call $~lib/math/NativeMath.pow
f64.const 0
f64.eq
call $~lib/object/Object.is<f64>
i32.const 0
i32.ne
i32.eqz
if
i32.const 0
Expand All @@ -43243,7 +43272,9 @@
f64.const -1
call $~lib/math/NativeMath.pow
f64.const -0
f64.eq
call $~lib/object/Object.is<f64>
i32.const 0
i32.ne
i32.eqz
if
i32.const 0
Expand Down
20 changes: 12 additions & 8 deletions tests/compiler/std/math.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -40016,8 +40016,9 @@
f64.const 0
f64.const 1
call $~lib/math/NativeMath.pow
f64.const 0
f64.ne
i64.reinterpret_f64
i64.const 0
i64.ne
if
i32.const 0
i32.const 1056
Expand All @@ -40029,8 +40030,9 @@
f64.const -0
f64.const 1
call $~lib/math/NativeMath.pow
f64.const -0
f64.ne
i64.reinterpret_f64
i64.const -9223372036854775808
i64.ne
if
i32.const 0
i32.const 1056
Expand Down Expand Up @@ -40160,8 +40162,9 @@
f64.const inf
f64.const -1
call $~lib/math/NativeMath.pow
f64.const 0
f64.ne
i64.reinterpret_f64
i64.const 0
i64.ne
if
i32.const 0
i32.const 1056
Expand All @@ -40173,8 +40176,9 @@
f64.const -inf
f64.const -1
call $~lib/math/NativeMath.pow
f64.const -0
f64.ne
i64.reinterpret_f64
i64.const -9223372036854775808
i64.ne
if
i32.const 0
i32.const 1056
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/std/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2695,8 +2695,8 @@ assert(NativeMath.pow(+Infinity, 0.0) == 1.0);
assert(NativeMath.pow(-Infinity, 0.0) == 1.0);
assert(NativeMath.pow(NaN, 0.0) == 1.0);

assert(NativeMath.pow(+0.0,+1.0) == +0.0);
assert(NativeMath.pow(-0.0,+1.0) == -0.0);
assert(Object.is(NativeMath.pow(+0.0,+1.0), +0.0));
assert(Object.is(NativeMath.pow(-0.0,+1.0), -0.0));
assert(NativeMath.pow(-1.0, 1.0) == -1.0);
assert(NativeMath.pow(+Infinity, 1.0) == +Infinity);
assert(NativeMath.pow(-Infinity, 1.0) == -Infinity);
Expand All @@ -2707,8 +2707,8 @@ assert(NativeMath.pow(-0.0,-1.0) == -Infinity);
assert(NativeMath.pow(-1.0,-1.0) == -1.0);
assert(NativeMath.pow( 0.5,-1.0) == +2.0);
assert(NativeMath.pow( 1.0,-1.0) == +1.0);
assert(NativeMath.pow(+Infinity,-1.0) == +0.0);
assert(NativeMath.pow(-Infinity,-1.0) == -0.0);
assert(Object.is(NativeMath.pow(+Infinity,-1.0), +0.0));
assert(Object.is(NativeMath.pow(-Infinity,-1.0), -0.0));
assert(isNaN(NativeMath.pow(NaN,-1.0)));

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