-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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 the polyfill of Math.fround. #12535
Conversation
As shown here: https://gist.github.com/shicks/7a97ec6b3f10212e60a89a7f6d2d097d?permalink_comment_id=4048135#gistcomment-4048135 the old polyfill was incorrect, because it was breaking ties *upwards* when rounding. The spec of `fround` requires to break ties to *even* instead. The new polyfill correctly breaks ties to even, even at the critical points of transitioning from subnormal to normal forms, and from finite to infinity. To perform ties-to-even, the code relies on the natural rounding that will happen when getting into the subnormal forms of (64-bit) `number`s. In addition, the new polyfill does not assume that `Math.log` will always return the best approximation. The spec of `Math.log` explicitly says that it may not return the best approximation.
Preview URLsFlawsNone! 🎉 External URLsURL:
(this comment was updated 2022-04-01 15:11:17.339589) |
@sjrd Note this: openwebdocs/project#27 |
Thank you for the link. I read the issue and followed some pointers from there. Following the rabbit hole, I ended up discovering Veltkamp's splitting algorithm, which improves the normal form case significantly. I'm not sure what to make of the linked issue wrt. this PR, though. Does that mean that no new PR updating MDN polyfills is going to be accepted, even until a solution is decided? If there is a chance for this to be merged, I'll update the PR with our newest implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be slow @sjrd . I think that since we have a link to the core-js polyfill in this page, we should delete this polyfill. Although we don't unfortunately have a very clear policy here, this is more or less in line with our recent practice.
A polyfill is available in core-js, and already referenced in the See also section.
All right. I added a commit that removes the Polyfill section entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @sjrd !
Summary
Fix the polyfill of
Math.fround
that does not rely onFloat32Array
.Motivation
As shown here:
https://gist.github.com/shicks/7a97ec6b3f10212e60a89a7f6d2d097d?permalink_comment_id=4048135#gistcomment-4048135
the old polyfill was incorrect, because it was breaking ties upwards when rounding. The spec of
fround
requires to break ties to even instead.The new polyfill correctly breaks ties to even, even at the critical points of transitioning from subnormal to normal forms, and from finite to infinity.
To perform ties-to-even, the code relies on the natural rounding that will happen when getting into the subnormal forms of (64-bit)
number
s.In addition, the new polyfill does not assume that
Math.log
will always return the best approximation. The spec ofMath.log
explicitly says that it may not return the best approximation.Supporting details
Metadata