Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt.toDouble() produces Infinity instead of -Infinity on large negative values. #36105

Closed
fishythefish opened this issue Mar 4, 2019 · 1 comment
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@fishythefish
Copy link
Member

fishythefish commented Mar 4, 2019

BigInt.toDouble() fails to convert large negative values to -Infinity. Instead, it produces Infinity for both positive and negative values. A small repro:

void main() {
  BigInt positive = BigInt.from(10).pow(309);
  BigInt negative = -positive;
  print(positive.toDouble()); // Correctly produces `Infinity`.
  print(negative.toDouble()); // Incorrectly produces `Infinity` instead of `-Infinity`.
}

This breaks constant folding in dart2js and may cause issues elsewhere. (Confirmed this behavior for the VM and dart2js backends; unsure about others.)

Dart VM version: 2.2.0-dev.2.1+google3-v2.2.0.dev.2.1 (google3) on "linux_x64"

@fishythefish fishythefish added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core labels Mar 4, 2019
@fishythefish fishythefish assigned fishythefish and lrhn and unassigned fishythefish Mar 4, 2019
@lrhn
Copy link
Member

lrhn commented Mar 5, 2019

Well spotted. The bigint_patch.dart file contains an overflow check:

if (length - 53 > maxDoubleExponent) return double.infinity;

which forgets to account for sign.

@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants