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

Fix Number.toExponential and Number.toFixed #1620

Merged
merged 6 commits into from
Oct 5, 2021

Conversation

nrabulinski
Copy link
Contributor

This Pull Request closes #1602.

It makes toExponential and toFixed methods on Number compliant with the specification.

One of the tests in toExponential currently fails. This is something that's blocked by rust-lang/rust#89493, unless we were to implement the exponential string algorithm ourselves.

@raskad
Copy link
Member

raskad commented Oct 3, 2021

Test262 conformance changes:

Test result master count PR count difference
Total 80,930 80,930 0
Passed 33,364 33,388 +24
Ignored 15,898 15,898 0
Failed 31,668 31,644 -24
Panics 0 0 0
Conformance 41.23% 41.26% +0.03%
Fixed tests (24):
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.4_T01.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.4_T01.js (previously Failed)
test/built-ins/Number/prototype/toFixed/range.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toFixed/range.js (previously Failed)
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.3_T01.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.3_T01.js (previously Failed)
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.3_T02.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.3_T02.js (previously Failed)
test/built-ins/Number/prototype/toExponential/return-abrupt-tointeger-fractiondigits-symbol.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/return-abrupt-tointeger-fractiondigits-symbol.js (previously Failed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-0.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-0.js (previously Failed)
test/built-ins/Number/prototype/toExponential/range.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/range.js (previously Failed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-not-0.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-not-0.js (previously Failed)
test/built-ins/Number/prototype/toExponential/return-abrupt-tointeger-fractiondigits.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/return-abrupt-tointeger-fractiondigits.js (previously Failed)
test/built-ins/Number/prototype/toExponential/infinity.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/infinity.js (previously Failed)
test/built-ins/Number/prototype/toExponential/undefined-fractiondigits.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/undefined-fractiondigits.js (previously Failed)
test/built-ins/Number/prototype/toExponential/tointeger-fractiondigits.js [strict mode] (previously Failed)
test/built-ins/Number/prototype/toExponential/tointeger-fractiondigits.js (previously Failed)

boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
@raskad
Copy link
Member

raskad commented Oct 3, 2021

Regarding the one failing test; I think we should merge this without that one.

But we may have an easier solution that to fix the issues in std. We already use ryu-js crate that converts numbers to strings. Conveniently the repository for the crate is in the boa-dev org: https://github.com/boa-dev/ryu-js ;)

Without looking further into it, my idea would be to implement the functionality of num_to_exponential and num_to_exponential_with_precision there. @HalidOdat I think you probably know the most about this, do you think we should try to do that, or is ryu-js not the right place?

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@raskad raskad requested a review from jedel1043 October 4, 2021 18:04
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Just a small nitpick I have about the utility functions

boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
@nrabulinski
Copy link
Contributor Author

Actually I just realized that there's another case which isn't covered by any 262 test and that's (1.0).toExponential(), which should return 1e+0 but returned 1e0 for us 😄

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Great work!

@jedel1043
Copy link
Member

Actually I just realized that there's another case which isn't covered by any 262 test and that's (1.0).toExponential(), which should return 1e+0 but returned 1e0 for us 😄

Oh, that can be filed on the test262 repo

@jedel1043 jedel1043 merged commit 4e2d195 into boa-dev:master Oct 5, 2021
@jedel1043 jedel1043 added this to the v0.14.0 milestone Oct 5, 2021
@jedel1043 jedel1043 added bug Something isn't working builtins PRs and Issues related to builtins/intrinsics Hacktoberfest Hacktoberfest 2021 - https://hacktoberfest.digitalocean.com labels Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working builtins PRs and Issues related to builtins/intrinsics Hacktoberfest Hacktoberfest 2021 - https://hacktoberfest.digitalocean.com
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Number.toExponential and Number.toFixed
3 participants