Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Incorrect JS number-to-string conversion for radices other than 10 #12764

Closed
wilkinson opened this issue Nov 22, 2014 · 2 comments
Closed

Incorrect JS number-to-string conversion for radices other than 10 #12764

wilkinson opened this issue Nov 22, 2014 · 2 comments

Comments

@wilkinson
Copy link

Problem

The Number.prototype.toString method is not computing correct results (which are defined here as "the results returned by command-line debugging shells for JavaScriptCore, Spidermonkey, and V8 as well as the developer consoles inside Chrome, Firefox, and Safari").

Test cases

(0.001).toString(16)   // returns "0",  but should return "0.004189374bc6a7f"
(1.001).toString(16)   // returns "1",  but should return "1.004189374bc6a"
(-0.001).toString(16)  // returns "-0", but should return "-0.004189374bc6a7f"
(0.0005).toString(16)  // returns "0",  but should return "0.0020c49ba5e353f8"

Hypothesis

Somehow, this conversion is not being handled by JavaScriptCore like it should be, because these results are computed correctly in the command-line JSC debugging shell available on OS X and in the developer console in Safari.

@wilkinson
Copy link
Author

I forgot to include a test case for a different base, but here's some more weirdness for you:

(0.001).toString(15)  // returns "0"

Firefox and Safari return "0.0035959595959596". Chrome returns "0.0035959595959594a82e42367e21e1d8a784b9036702eccb87c7951c0ebcacd6e0480c0b9d173621125150b5b233085db20118a7eb956e43e792a1dcee91d945d746571c27c02bc9938ac3a970b6ca56e2e64ad745857557456d19b73b4a1678692eb04b03bd4e9c5eeb4d861ee9d3eb30cce38bc794b902b1a2d994cec6a1a688a6131a49963874b41734bc5e7e62629a9446b0511ab51eb611be6e1e8bb90582e40dea5d54343a37e88dcd288d65c09b9e5c49b8c6959607e0393b89763e98cd981359cc784ec59d21443690c5a147c7d7ee40530b495c76096ae1e7e6b6a33bd843b57e1a5a1b1096d154145a980a0cb098857a84724848a158734cd59543a860848774a7d6eeb5e7a2a03bd88226640d881be791823ad38da7c1d6a0e28868417c390a4429533e26b792ea8056b93e3dbcd499e89e15d30ed1cc2b2b879ddb238531b658380654ace2935bd7c1ee2a3409bbacd7aea72dc91081dcc2119ecb24b8d567e4cad70b9ab615c71d4edeed47c2ae96215cdbe72630bc1762bca42bd905a8197e7cc19365786cdbc51ea3b9594c9803dd049088b6e176e054bac31b7ada0b10137a8e8308321a76172250c8bd825ebeebb28b98d2a388d674cd21128ab84dc813c3188ce59b6c99840ae9b1612bdb1c8266a7073589d8a52588b0b22ea3de2b782624b02552d1a64140a24183a811594aa3b6cd037a5a403033a306e472381cc00787311584b334c9e878730d44b32c77cc8e6ee51bd0c4e2c60717dcaa94d8d".

I'm not sure why V8 goes crazy there, but according to page 48 of the ES5.1 specification, the correct result is definitely not "0".

@vitallium
Copy link
Collaborator

Please upgrade to PhantomJS 2.0. 1.9.x is no longer supported, and known to have many crasher bugs that are fixed in 2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants