Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions std/assembly/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,16 +1575,15 @@ export namespace NativeMath {
var uy = reinterpret<u64>(y);
var ex = <i64>(ux >> 52 & 0x7FF);
var ey = <i64>(uy >> 52 & 0x7FF);
var sx = ux >> 63;
var sm = ux & 0x8000000000000000;
var uy1 = uy << 1;
if (uy1 == 0 || ex == 0x7FF || isNaN<f64>(y)) {
let m = x * y;
return m / m;
}
var ux1 = ux << 1;
if (ux1 <= uy1) {
if (ux1 == uy1) return 0 * x;
return x;
return x * f64(ux1 != uy1);
}
if (!ex) {
ex -= builtin_clz<i64>(ux << 12);
Expand Down Expand Up @@ -1622,8 +1621,7 @@ export namespace NativeMath {
} else {
ux >>= -ex + 1;
}
ux |= sx << 63;
return reinterpret<f64>(ux);
return reinterpret<f64>(ux | sm);
}

export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c
Expand Down Expand Up @@ -2884,16 +2882,15 @@ export namespace NativeMathf {
var uy = reinterpret<u32>(y);
var ex = <i32>(ux >> 23 & 0xFF);
var ey = <i32>(uy >> 23 & 0xFF);
var sx = ux & 0x80000000;
var sm = ux & 0x80000000;
var uy1 = uy << 1;
if (uy1 == 0 || ex == 0xFF || isNaN<f32>(y)) {
let m = x * y;
return m / m;
}
var ux1 = ux << 1;
if (ux1 <= uy1) {
if (ux1 == uy1) return 0 * x;
return x;
return x * f32(ux1 != uy1);
}
if (!ex) {
ex -= builtin_clz<u32>(ux << 9);
Expand Down Expand Up @@ -2931,8 +2928,7 @@ export namespace NativeMathf {
} else {
ux >>= -ex + 1;
}
ux |= sx;
return reinterpret<f32>(ux);
return reinterpret<f32>(ux | sm);
}

export function rem(x: f32, y: f32): f32 { // see: musl/src/math/remquof.c
Expand Down
34 changes: 10 additions & 24 deletions tests/compiler/binary.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1288,16 +1288,12 @@
local.get $7
i32.le_u
if
local.get $0
local.get $9
local.get $7
i32.eq
if
f32.const 0
local.get $0
f32.mul
return
end
local.get $0
i32.ne
f32.convert_i32_u
f32.mul
return
end
local.get $4
Expand Down Expand Up @@ -1460,8 +1456,6 @@
local.get $2
local.get $6
i32.or
local.set $2
local.get $2
f32.reinterpret_i32
)
(func $~lib/math/NativeMathf.pow (param $0 f32) (param $1 f32) (result f32)
Expand Down Expand Up @@ -2121,8 +2115,8 @@
i64.and
local.set $5
local.get $2
i64.const 63
i64.shr_u
i64.const -9223372036854775808
i64.and
local.set $6
local.get $3
i64.const 1
Expand Down Expand Up @@ -2163,16 +2157,12 @@
local.get $7
i64.le_u
if
local.get $0
local.get $9
local.get $7
i64.eq
if
f64.const 0
local.get $0
f64.mul
return
end
local.get $0
i64.ne
f64.convert_i32_u
f64.mul
return
end
local.get $4
Expand Down Expand Up @@ -2338,11 +2328,7 @@
end
local.get $2
local.get $6
i64.const 63
i64.shl
i64.or
local.set $2
local.get $2
f64.reinterpret_i64
)
(func $start:binary
Expand Down
Loading