Skip to content

Commit ee5481b

Browse files
committed
#354 Avoid bug in v8 Maglev compiler.
Use mathfloor rather than bitwise floor in round function.
1 parent 65156eb commit ee5481b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

bignumber.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@
14231423
n = xc[ni = 0];
14241424

14251425
// Get the rounding digit at index j of n.
1426-
rd = n / pows10[d - j - 1] % 10 | 0;
1426+
rd = mathfloor(n / pows10[d - j - 1] % 10);
14271427
} else {
14281428
ni = mathceil((i + 1) / LOG_BASE);
14291429

@@ -1454,7 +1454,7 @@
14541454
j = i - LOG_BASE + d;
14551455

14561456
// Get the rounding digit at index j of n.
1457-
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
1457+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
14581458
}
14591459
}
14601460

bignumber.mjs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ function clone(configObject) {
14201420
n = xc[ni = 0];
14211421

14221422
// Get the rounding digit at index j of n.
1423-
rd = n / pows10[d - j - 1] % 10 | 0;
1423+
rd = mathfloor(n / pows10[d - j - 1] % 10);
14241424
} else {
14251425
ni = mathceil((i + 1) / LOG_BASE);
14261426

@@ -1451,7 +1451,7 @@ function clone(configObject) {
14511451
j = i - LOG_BASE + d;
14521452

14531453
// Get the rounding digit at index j of n.
1454-
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
1454+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
14551455
}
14561456
}
14571457

@@ -2000,7 +2000,12 @@ function clone(configObject) {
20002000
}
20012001

20022002
// x < y? Point xc to the array of the bigger number.
2003-
if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
2003+
if (xLTy) {
2004+
t = xc;
2005+
xc = yc;
2006+
yc = t;
2007+
y.s = -y.s;
2008+
}
20042009

20052010
b = (j = yc.length) - (i = xc.length);
20062011

@@ -2154,7 +2159,14 @@ function clone(configObject) {
21542159
ycL = yc.length;
21552160

21562161
// Ensure xc points to longer array and xcL to its length.
2157-
if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
2162+
if (xcL < ycL) {
2163+
zc = xc;
2164+
xc = yc;
2165+
yc = zc;
2166+
i = xcL;
2167+
xcL = ycL;
2168+
ycL = i;
2169+
}
21582170

21592171
// Initialise the result array with zeros.
21602172
for (i = xcL + ycL, zc = []; i--; zc.push(0));
@@ -2275,7 +2287,12 @@ function clone(configObject) {
22752287
b = yc.length;
22762288

22772289
// Point xc to the longer array, and b to the shorter length.
2278-
if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
2290+
if (a - b < 0) {
2291+
t = yc;
2292+
yc = xc;
2293+
xc = t;
2294+
b = a;
2295+
}
22792296

22802297
// Only start adding at yc.length - 1 as the further digits of xc can be ignored.
22812298
for (a = 0; b;) {
@@ -2561,7 +2578,12 @@ function clone(configObject) {
25612578
intDigits = isNeg ? intPart.slice(1) : intPart,
25622579
len = intDigits.length;
25632580

2564-
if (g2) i = g1, g1 = g2, g2 = i, len -= i;
2581+
if (g2) {
2582+
i = g1;
2583+
g1 = g2;
2584+
g2 = i;
2585+
len -= i;
2586+
}
25652587

25662588
if (g1 > 0 && len > 0) {
25672589
i = len % g1 || g1;

0 commit comments

Comments
 (0)