Skip to content

Commit e801081

Browse files
committed
wip
1 parent a022591 commit e801081

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"engineStrict": true,
2727
"dependencies": {
28+
"as-float": "^1.0.0",
2829
"binaryen": "116.0.0-nightly.20240114",
2930
"long": "^5.2.4"
3031
},

src/glue/js/float.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ declare function f32_as_i32(value: f32): i32;
77
declare function i32_as_f32(value: i32): f32;
88
declare function f64_as_i64(value: f64): i64;
99
declare function i64_as_f64(value: i64): f64;
10+
declare function f64_pow(value: f64, exponent: f64): f64;

src/glue/js/float.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @license Apache-2.0
44
*/
55

6+
import { f64_pow } from "as-float";
7+
68
/* eslint-disable no-undef */
79

810
const F64 = new Float64Array(1);
@@ -29,3 +31,5 @@ globalThis.i64_as_f64 = function i64_as_f64(value) {
2931
I32[1] = i64_high(value);
3032
return F64[0];
3133
};
34+
35+
globalThis.f64_pow = f64_pow;

src/util/math.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ export function isPowerOf2(x: i32): bool {
1111
export function accuratePow64(x: f64, y: f64): f64 {
1212
if (!ASC_TARGET) { // ASC_TARGET == JS
1313
// Engines like V8, WebKit and SpiderMonkey uses powi fast path if exponent is integer
14-
// This speculative optimization leads to loose precisions like 10 ** -5 != 1e-5 anymore.
15-
// For avoid this behaviour we are forcing exponent
16-
// to fractional form and compensate this afterwards.
17-
if (isFinite(y) && y <= -2 && Math.trunc(y) == y) {
18-
return Math.pow(x, y + 0.5) / Math.pow(x, 0.5);
19-
}
14+
// This speculative optimization leads to loose precisions like 10 ** -5 != 1e-5 anymore
15+
// and introduces inconsistencies between different engines and versions
16+
// For avoid this behavior we using bootstrap f64_pow function.
17+
return f64_pow(x, y);
2018
}
2119
return Math.pow(x, y);
2220
}

0 commit comments

Comments
 (0)