Skip to content

Commit 1924d64

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[corelib] Fix for BigInt.toDouble() crash
Bug: 41819 Change-Id: Ied24b42728e1da0d713fe971386d4ef6a023333e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147349 Reviewed-by: Bob Nystrom <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 755a315 commit 1924d64

File tree

8 files changed

+20
-6
lines changed

8 files changed

+20
-6
lines changed

sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ class _BigIntImpl implements BigInt {
28252825
// There is already one in the cachedBits.
28262826
roundUp();
28272827
} else {
2828-
for (int i = digitIndex; digitIndex >= 0; i--) {
2828+
for (int i = digitIndex; i >= 0; i--) {
28292829
if (_digits[i] != 0) {
28302830
roundUp();
28312831
break;

sdk/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ class _BigIntImpl implements BigInt {
27382738
// There is already one in the cachedBits.
27392739
roundUp();
27402740
} else {
2741-
for (int i = digitIndex; digitIndex >= 0; i--) {
2741+
for (int i = digitIndex; i >= 0; i--) {
27422742
if (_digits[i] != 0) {
27432743
roundUp();
27442744
break;

sdk/lib/_internal/vm/lib/bigint_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ class _BigIntImpl implements BigInt {
24092409
// There is already one in the cachedBits.
24102410
roundUp();
24112411
} else {
2412-
for (int i = digitIndex; digitIndex >= 0; i--) {
2412+
for (int i = digitIndex; i >= 0; i--) {
24132413
if (_digits[i] != 0) {
24142414
roundUp();
24152415
break;

sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ class _BigIntImpl implements BigInt {
28302830
// There is already one in the cachedBits.
28312831
roundUp();
28322832
} else {
2833-
for (int i = digitIndex; digitIndex >= 0; i--) {
2833+
for (int i = digitIndex; i >= 0; i--) {
28342834
if (_digits[i] != 0) {
28352835
roundUp();
28362836
break;

sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ class _BigIntImpl implements BigInt {
27602760
// There is already one in the cachedBits.
27612761
roundUp();
27622762
} else {
2763-
for (int i = digitIndex; digitIndex >= 0; i--) {
2763+
for (int i = digitIndex; i >= 0; i--) {
27642764
if (_digits[i] != 0) {
27652765
roundUp();
27662766
break;

sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ class _BigIntImpl implements BigInt {
24132413
// There is already one in the cachedBits.
24142414
roundUp();
24152415
} else {
2416-
for (int i = digitIndex; digitIndex >= 0; i--) {
2416+
for (int i = digitIndex; i >= 0; i--) {
24172417
if (_digits[i] != 0) {
24182418
roundUp();
24192419
break;

tests/corelib/bigint_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,13 @@ void testFromToDouble() {
10391039

10401040
Expect.equals(BigInt.zero, new BigInt.from(0.9999999999999999));
10411041
Expect.equals(BigInt.zero, new BigInt.from(-0.9999999999999999));
1042+
1043+
// Regression test for http://dartbug.com/41819
1044+
// Rounding edge case where last digit causes rounding.
1045+
Expect.equals(-3.69616463331328e+27,
1046+
BigInt.parse("-3696164633313280000000000000").toDouble());
1047+
Expect.equals(-3.6961646333132803e+27,
1048+
BigInt.parse("-3696164633313280000000000001").toDouble());
10421049
}
10431050

10441051
main() {

tests/corelib_2/bigint_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,13 @@ void testFromToDouble() {
10391039

10401040
Expect.equals(BigInt.zero, new BigInt.from(0.9999999999999999));
10411041
Expect.equals(BigInt.zero, new BigInt.from(-0.9999999999999999));
1042+
1043+
// Regression test for http://dartbug.com/41819
1044+
// Rounding edge case where last digit causes rounding.
1045+
Expect.equals(-3.69616463331328e+27,
1046+
BigInt.parse("-3696164633313280000000000000").toDouble());
1047+
Expect.equals(-3.6961646333132803e+27,
1048+
BigInt.parse("-3696164633313280000000000001").toDouble());
10421049
}
10431050

10441051
main() {

0 commit comments

Comments
 (0)