Skip to content

fix: Don't override type-native floor/ceil within tolerance of value#3369

Merged
josdejong merged 3 commits into
josdejong:developfrom
gwhitney:fix/floor_tol
Jan 30, 2025
Merged

fix: Don't override type-native floor/ceil within tolerance of value#3369
josdejong merged 3 commits into
josdejong:developfrom
gwhitney:fix/floor_tol

Conversation

@gwhitney
Copy link
Copy Markdown
Collaborator

@gwhitney gwhitney commented Jan 28, 2025

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, and fix.

Resolves #3247.

Copy link
Copy Markdown
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread src/function/arithmetic/ceil.js
@josdejong josdejong merged commit 773a5c5 into josdejong:develop Jan 30, 2025
@josdejong
Copy link
Copy Markdown
Owner

Published now in v14.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bignumber floor issue or misunderstanding of relTol ?

2 participants