[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 <rnystrom@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams 2020-05-09 00:22:16 +00:00 committed by commit-bot@chromium.org
parent 755a315dc5
commit 1924d64351
8 changed files with 20 additions and 6 deletions

View file

@ -2825,7 +2825,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -2738,7 +2738,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -2409,7 +2409,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -2830,7 +2830,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -2760,7 +2760,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -2413,7 +2413,7 @@ class _BigIntImpl implements BigInt {
// There is already one in the cachedBits.
roundUp();
} else {
for (int i = digitIndex; digitIndex >= 0; i--) {
for (int i = digitIndex; i >= 0; i--) {
if (_digits[i] != 0) {
roundUp();
break;

View file

@ -1039,6 +1039,13 @@ void testFromToDouble() {
Expect.equals(BigInt.zero, new BigInt.from(0.9999999999999999));
Expect.equals(BigInt.zero, new BigInt.from(-0.9999999999999999));
// Regression test for http://dartbug.com/41819
// Rounding edge case where last digit causes rounding.
Expect.equals(-3.69616463331328e+27,
BigInt.parse("-3696164633313280000000000000").toDouble());
Expect.equals(-3.6961646333132803e+27,
BigInt.parse("-3696164633313280000000000001").toDouble());
}
main() {

View file

@ -1039,6 +1039,13 @@ void testFromToDouble() {
Expect.equals(BigInt.zero, new BigInt.from(0.9999999999999999));
Expect.equals(BigInt.zero, new BigInt.from(-0.9999999999999999));
// Regression test for http://dartbug.com/41819
// Rounding edge case where last digit causes rounding.
Expect.equals(-3.69616463331328e+27,
BigInt.parse("-3696164633313280000000000000").toDouble());
Expect.equals(-3.6961646333132803e+27,
BigInt.parse("-3696164633313280000000000001").toDouble());
}
main() {