-
Notifications
You must be signed in to change notification settings - Fork 717
Implement Math.sumPrecise using compensated summation #1779
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
base: static_h
Are you sure you want to change the base?
Conversation
|
Hi, thank you for putting this up! We've discussed this internally and we think it would be better to implement this using the JS polyfill from the github proposal page. Also, in general, new features like this should be added to our Static Hermes branch ( Can you please update this PR accordingly? We will be happy to review it, thanks! |
Implements Math.sumPrecise as requested in PR facebook#1779 feedback. Uses the JavaScript polyfill from the TC39 proposal instead of native C++ implementation, as suggested by the maintainer. The implementation: - Uses Shewchuk's algorithm for exact floating point addition - Handles special cases for -0, Infinity, and NaN correctly - Supports any iterable via Symbol.iterator protocol - Throws TypeError for non-iterables - Matches the TC39 proposal specification Test coverage includes basic summation, floating point precision, special values, and iterator protocol support.
03dd360 to
6082ea1
Compare
|
Thank you for the feedback! I've updated the PR to implement Math.sumPrecise using the JavaScript polyfill approach as suggested.
The implementation now:
The polyfill is automatically included in the InternalBytecode during build and works correctly with static Hermes. Please let me know if any further changes are needed! |
|
Thanks for updating the PR! A couple of comments:
Thanks again for working on this! |
- Document spec deviations (missing iteratorClose, simplified TypeError handling) in doc/Features.md - Add comprehensive test262-based tests including generators, custom iterators, and type error cases - Include Python Software Foundation copyright attribution for fsum algorithm - Fix function name property and improve error handling for non-number types
|
@tsaichien Thank you for the feedback. I've addressed all three points - documented the spec differences, added the license attribution, and included additional tests. Please let me know if anything else is needed. |
|
I don't see the updates files. Can you please update the PR and let me know? Thanks! |
- Replace invalid '0,' comma operator syntax with proper destructuring - Use Number() instead of unary + for type conversion per spec - Ensures proper JavaScript syntax in all destructuring assignments
06ed76b to
2a24c2a
Compare
|
@tsaichien Sorry for the confusion - the PR branch was out of sync. Now updated with all 3 files and syntax fixes. |
|
No worries. The language feature doc looks good, thanks! I believe the PR is still missing the BSD license for the polyfill, and the polyfill tests from the proposal github. Please add these to the PR, thanks. |
|
@tsaichien Added BSD license and test cases from TC39 proposal as requested. |
Implements
Math.sumPreciseper TC39 Stage 3 specification.Fixes #1778
Algorithm
Shewchuk's Two-Sum for exact floating-point arithmetic
Changes
lib/VM/JSLib/Math.cpp: Core implementation (~250 lines)include/hermes/VM/PredefinedStrings.def: Symbol registrationtest/hermes/math-sumprecise.js: Test suite (20 cases)Performance
Testing
Notes
This is a draft PR pending maintainer feedback on issue #1778.