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

Numbers up to 10^21 shouldn't be displayed exponentially (Fixes #2751) #3635

Merged
merged 1 commit into from
Sep 15, 2017
Merged

Conversation

xiaoyinl
Copy link
Contributor

@xiaoyinl xiaoyinl commented Sep 3, 2017

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.

@xiaoyinl xiaoyinl changed the base branch from master to release/1.7 September 3, 2017 10:07
maxOutDigits = g_rgcchSig[radix];
__analysis_assume(maxOutDigits > 0);

if (wExp2 < -60 || wExp2 > 60)
if (wExp10 < -21 || wExp10 > 21)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exp2 is already calculated above. Could we use that for comparison instead of calculating expensive Exp10?

@xiaoyinl
Copy link
Contributor Author

xiaoyinl commented Sep 4, 2017

@obastemur I changed it to compare dbl with 1e+21 directly, since Exp10 isn't used elsewhere. Also #2751 has further discussion on what to do for numbers larger than 10^21. I'll update the code and the test cases if ChakraCore wants to follow the behavior of other engines.

@obastemur
Copy link
Collaborator

obastemur commented Sep 11, 2017

@xiaoyinl could you please update the output under test/Number/toString_3.baseline

09:11:35 Output: (at line 119)
09:11:35 ----------------------------
09:11:35 n.toString(8):  154327115334273650000000
09:11:35 ----------------------------
09:11:35 Expected Output:
09:11:35 ----------------------------
09:11:35 n.toString(8):  1.5432711533427365(e+23)
09:11:35 ----------------------------
09:11:35 exit code: 0

@MSLaguana
Copy link
Contributor

Isn't the exponential form correct in that case?

@obastemur
Copy link
Collaborator

obastemur commented Sep 11, 2017

Isn't the exponential form correct in that case?

Correct.

@obastemur
Copy link
Collaborator

@xiaoyinl @MSLaguana test case should be updated to 154327115334273650000000 ..

The reason is, we ask for 1e21.toString(8) So, the output we see there is <= 1e21. So the output after this PR is the correct output.

@xiaoyinl
Copy link
Contributor Author

xiaoyinl commented Sep 12, 2017

@obastemur @MSLaguana Done. The remaining question is what to do if the number is > 1e21. @littledan says other engines never switch to exponential notation for radix not 10, regardless of how large it is. Do you want ChakraCore to adopt this behavior?

@obastemur
Copy link
Collaborator

/cc @bterlson

@obastemur
Copy link
Collaborator

At this point; if tests pass, squashing commits could be nice

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.

This fixes #2751.
@dilijev
Copy link
Contributor

dilijev commented Sep 15, 2017

Tests pass. I'll adopt this and merge it in after it passed tests internally.

I have added some follow-up tasks:

@chakrabot chakrabot merged commit fb255ed into chakra-core:release/1.7 Sep 15, 2017
chakrabot pushed a commit that referenced this pull request 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 pull request 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.
@xiaoyinl xiaoyinl deleted the num_exp branch September 15, 2017 04:30
chakrabot pushed a commit that referenced this pull request 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 pull request 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants