Math library accuracy + performance improvements#512
Open
ecc521 wants to merge 1 commit intoscratchfoundation:developfrom
Open
Math library accuracy + performance improvements#512ecc521 wants to merge 1 commit intoscratchfoundation:developfrom
ecc521 wants to merge 1 commit intoscratchfoundation:developfrom
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
6d3a22c to
8694f87
Compare
30e30aa to
402deef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This corresponds to a 2019 PR that should have been merged a log time ago. It addresses two performance & accuracy issues in the previous scratch-vm repository that remain in this repository (2198 and 2199) .
scratch3_operators.js & math-util.js: Floating-point bounding for trigonometric operations (sin/cos/tan) was relying on parseFloat(..., 10). This is replaced with scaled floating-point arithmetic Math.round(... * 1e10) / 1e10. Operators are additionally bounded by % 360 to prevent IEEE-754 precision loss at large scale values.
cast.js: The Cast.isInt boundary check utilized parseInt(val, 10). For stringified values in scientific notation (e.g. 1e22), parseInt parsed out "1", erroneously evaluating the float as non-integer. Modulo constraint (val % 1 === 0) evaluates correctly without stringification. This change is practically irrelevant but technically a bug fix.
Verification
Unit parity with Scratch native tests verified (npm run tap:unit).
blocks_operators and blocks_operators_infinity tests fully pass, ensuring proper edge case constraints for non-standard numerics (NaN, Infinity, -0).