fix: Don't override type-native floor/ceil within tolerance of value#3369
Merged
Conversation
josdejong
reviewed
Jan 29, 2025
Owner
josdejong
left a comment
There was a problem hiding this comment.
Awesome, this is indeed an important fix and I would like to publish this asap!
I made one inline comment, can you have a look at that?
Owner
|
Published now in |
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.
Formerly, it was sufficient for a value x to be within tolerance of its rounded value for that to override the floor/ceil provided by the type of x. Now, we only override that native floor/ceil when the rounded value is within tolerance and the floor/ceil value is distinct from x as perceived by the tolerance. When both the rounded value and the floor/ceil are within tolerance, there is no reason to prefer the rounded value over what the native floor/ceil is telling us.
Practically speaking, this change prevents mathjs from becoming confused by the tolerances and reporting that the floor of 1234567890123.5 is 1234567890124. Similar issues for BigNumbers are also fixed. Note this means that with the default tolerances, which are very loose by BigNumber standards, for large BigNumbers mathjs will end up just falling back to the native BigNumber floor/ceil (since mathjs will always consider a large BigNumber to be "nearly equal to" both its floor and its ceiling). That seems like preferable behavior to always overriding them.
Of my outstanding PRs, this is probably both the lightest weight and the most important, as it corrects numerous questionable return values of
floor,ceil, andfix.Resolves #3247.