JDK-8030200 : Wrong result for Number.prototype.toString() for certain radix/inputs
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_ubuntu
  • Submitted: 2013-12-13
  • Updated: 2014-07-29
  • Resolved: 2014-04-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b10Fixed
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
Number.prototype.toString() gives wrong results for certain input parameters. See http://code.google.com/p/v8/issues/detail?id=3025 for original bug report in V8.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
jjs> 0x8000000000000800.toString(5)

Expected: 1104332401304422434310342411
Actual: 1104332401304422434310444401


REPRODUCIBILITY :
This bug can be reproduced always.
Comments
I suggest following V8 here to accept a slight loss of precision in our toString algorithm as long as parseInt() converts back to the exact original number. To avoid loss of precision we would have to rewrite our algorithm using java.math.BigInteger, but to the best of my understanding that is not required by the ECMA spec.
31-03-2014