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

1e+19.toString(2) is displayed exponentially, but should be written out #2751

Closed
littledan opened this issue Mar 28, 2017 · 3 comments
Closed
Labels
Milestone

Comments

@littledan
Copy link

The output given by ChakraCore is 1.00010101100011100100011000001001000100111101(e+63), but in three other engines, the correct answer of 1000101011000111001000110000010010001001111010000000000000000000 is provided. The spec states that with n (the base-10 exponent) between 0 and 21, the written out version should be used, rather than the exponential version.

@xiaoyinl
Copy link
Contributor

xiaoyinl commented Sep 3, 2017

@littledan Section 20.1.3.6 says if the radix is not 10, "the precise algorithm is implementation-dependent", but it should be a generalization of 7.1.12.1. I wonder how it's generalized. For example, it seems v8 and SpiderMonkey never use exponential notation when the radix isn't 10, even though the base 10 exponent is larger than 21, like this:

9.2323e+28.toString(2)
"1001010100100111111001011101100101000010011011010101000000000000000000000000000000000000000000000"

Should Chakra match this behavior too?

@littledan
Copy link
Author

@xiaoyinl It seems that SpiderMonkey, JSC and V8 all agree that it should be generalized in a way that never switches to exponential notation. If ChakraCore wants to have similar behavior to other engines, it could adopt that same behavior.

If the specification more specifically documented the 3/4 behavior, would that help ChakraCore?

cc @bterlson

@bterlson
Copy link
Contributor

bterlson commented Sep 5, 2017

@littledan any improvements to the spec in terms of reflecting reality is very helpful :)

chakrabot pushed a commit that referenced this issue Sep 15, 2017
…ponentially (Fixes #2751)

Merge pull request #3635 from xiaoyinl:num_exp

The spec section 7.1.12.1 requires that if a number's base 10 logarithm is <= 21, then it shouldn't use exponential notation when it's converted to String. The original code checks if the base 2 logarithm of the number is <= 60.

This fixes #2751.
chakrabot pushed a commit that referenced this issue Sep 15, 2017
… displayed exponentially (Fixes #2751)

Merge pull request #3635 from xiaoyinl:num_exp

The spec section 7.1.12.1 requires that if a number's base 10 logarithm is <= 21, then it shouldn't use exponential notation when it's converted to String. The original code checks if the base 2 logarithm of the number is <= 60.

This fixes #2751.
chakrabot pushed a commit that referenced this issue Oct 21, 2017
, #3740)

Merge pull request #3742 from xiaoyinl:never_use_exp

Other engines (SpiderMonkey, JSC and V8) never use exponential display for num.toString(radix) if radix is not 10, no matter how large num is. This PR updates the code and the test cases to match that behavior.

This PR fixes #3739 and fixes #3740.

See also: #2751, #3635.

/cc @dilijev @littledan @bterlson
chakrabot pushed a commit that referenced this issue Oct 21, 2017
…ot 10 (Fix #3739, #3740)

Merge pull request #3742 from xiaoyinl:never_use_exp

Other engines (SpiderMonkey, JSC and V8) never use exponential display for num.toString(radix) if radix is not 10, no matter how large num is. This PR updates the code and the test cases to match that behavior.

This PR fixes #3739 and fixes #3740.

See also: #2751, #3635.

/cc @dilijev @littledan @bterlson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants