mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:12:08 +00:00
[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:
parent
755a315dc5
commit
1924d64351
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue