Skip to content
Open
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
6 changes: 4 additions & 2 deletions decimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2595,11 +2595,13 @@
if (i == 0) rd = rd / 1000 | 0;
else if (i == 1) rd = rd / 100 | 0;
else if (i == 2) rd = rd / 10 | 0;
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999
|| rd == 5000 || rd == 0;
} else {
r = ((repeating || rm < 4) && rd + 1 == k ||
(!repeating && rm > 3) && rd + 1 == k / 2) &&
(d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
(d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1
|| (rd == k / 2 || rd == 0) && (d[di + 1] / k / 1000 | 0) == 0;
}
}

Expand Down
6 changes: 4 additions & 2 deletions decimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,11 +2591,13 @@ function checkRoundingDigits(d, i, rm, repeating) {
if (i == 0) rd = rd / 1000 | 0;
else if (i == 1) rd = rd / 100 | 0;
else if (i == 2) rd = rd / 10 | 0;
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999
|| rd == 5000 || rd == 0;
} else {
r = ((repeating || rm < 4) && rd + 1 == k ||
(!repeating && rm > 3) && rd + 1 == k / 2) &&
(d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
(d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1
|| (rd == k / 2 || rd == 0) && (d[di + 1] / k / 1000 | 0) == 0;
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/modules/ln.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ T('ln', function () {
t('NaN', String(Math.log(NaN)), 40, 4);
t('2.7182818284590452353602874713526624977572', '1', 39, 4);

// Correctly-rounded ln where the result lands just below a rounding tie
// (...d 4999...): these rounded up instead of down before the guard-digit
// fix in checkRoundingDigits.
t('4.25914212183600678912449997353532582823393815', '1.4490677601509316343', 20, 4);
t('1.6852358445909596506369573334700403721376594', '0.52190552112613867979', 20, 4);
t('147.901327174696092190385346999167895276772254', '4.9965453431362365587', 20, 4);
t('7.65606302212512952930223042181358382147654373', '2.0354978858468052277', 20, 4);
t('24.7812098757520159815273195615677780988161707', '3.2100856996964392732', 20, 4);

t('91247532.65728', '18.3290865106890306', 19, 1);
t('727579403.9', '20.40523369730819818291393006', 28, 3);
t('419065154.52076499608', '19.8535369658470908', 19, 2);
Expand Down