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

Fix int.toRadixString() for MIN_INT64 with --limit-ints-to-64-bits #31346

Closed
alexmarkov opened this Issue Nov 10, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@alexmarkov
Contributor

alexmarkov commented Nov 10, 2017

main() {
  final kMinInt64 = -9223372036854775808;

  print("$kMinInt64.toRadixString(2) = ${kMinInt64.toRadixString(2)}");
  print("$kMinInt64.toRadixString(3) = ${kMinInt64.toRadixString(3)}");
  print("$kMinInt64.toRadixString(10) = ${kMinInt64.toRadixString(10)}");
  print("$kMinInt64.toRadixString(16) = ${kMinInt64.toRadixString(16)}");
}

Output without --limit-ints-to-64-bits

-9223372036854775808.toRadixString(2) = -1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808.toRadixString(3) = -2021110011022210012102010021220101220222
-9223372036854775808.toRadixString(10) = -9223372036854775808
-9223372036854775808.toRadixString(16) = -8000000000000000

Output with --limit-ints-to-64-bits

-9223372036854775808.toRadixString(2) = -0
-9223372036854775808.toRadixString(3) = -1
-9223372036854775808.toRadixString(10) = -9223372036854775808
-9223372036854775808.toRadixString(16) = -0

For negative values int.toRadixString() negates the value and then treats it as non-negative (iterates while it is positive). It is not correct for MIN_INT64 (-9223372036854775808) value after switching to fixed-size int64: -MIN_INT64 == MIN_INT64, so it is still negative after negation.

/cc @floitschG

@a-siva a-siva added the area-library label Nov 13, 2017

@alexmarkov alexmarkov self-assigned this Jan 17, 2018

@whesse whesse closed this in 2e5264d Jan 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment