Skip to content

Commit b404098

Browse files
committed
fix: avoid powi opt in js engine only when exponent <= 2
1 parent f16b08f commit b404098

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/util/math.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ 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 ** 208 != 1e208
15-
// or/and 10 ** -5 != 1e-5 anymore. For avoid this behaviour we are forcing exponent
14+
// This speculative optimization leads to loose precisions like 10 ** -5 != 1e-5 anymore.
15+
// For avoid this behaviour we are forcing exponent
1616
// to fractional form and compensate this afterwards.
17-
if (isFinite(y) && Math.abs(y) >= 2 && Math.trunc(y) == y) {
18-
if (y < 0) {
19-
return Math.pow(x, y + 0.5) / Math.pow(x, 0.5);
20-
} else {
21-
return Math.pow(x, y - 0.5) * Math.pow(x, 0.5);
22-
}
17+
if (isFinite(y) && y <= 2 && Math.trunc(y) == y) {
18+
return Math.pow(x, y + 0.5) / Math.pow(x, 0.5);
2319
}
2420
}
2521
return Math.pow(x, y);

0 commit comments

Comments
 (0)