Repository navigation
Math.max(-0, 0) is 0 and Math.min(0, -0) is -0, in either order - #104
Merged
Merged
Conversation
`>` and `<` do not tell -0 from +0, so the answer depended on the argument order: Math.max(-0, 0) gave -0 and Math.min(0, -0) gave 0. With the two zeros compared, +0 is the larger, as in JavaScript. The test makes its zeros at run time (`-0` is the integer 0). It needs the compiler fix for folded constants passed as rest arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Bug
>and<don't tell-0from+0, soMath.max/Math.minof the two zeros depended on argument order:Math.max(-0, 0)0-0Math.max(0, -0)00Math.min(0, -0)-00Math.min(-0, 0)-0-0Fix
When the candidate and the current result are both zero, the sign decides:
+0is the larger. NaN handling andMath.max()/Math.min()with no arguments are unchanged.Tests
tests/math_max_min.ts: every order of the two zeros,max(-0, -0),min(0, 0), and zeros against other numbers. The zeros are made at run time, because-0written as a literal is the integer 0.Math.max(nz, nz)withconst nz = -0.0 * scalegot a one-element array of garbage.tests.ps1release compile + jit for gc/rc/none/own all pass, and the declarations match. The debug pass was not run.🤖 Generated with Claude Code