Fix rationalize([T,] x::Rational; ...)#61057
Open
lvlte wants to merge 4 commits intoJuliaLang:masterfrom
Open
Conversation
- Fix `tol` ignored when `T` is not specified. - Specific implementation for rationals (vs floats): return `x` unless the given `tol` is significant enough to reduce the magnitude of its components, in which case rationalize `float(x)` instead. - Reset the main function specific to floats only: if rational, the error and tolerance terms (their components) are very likely to overflow as they converge towards zero. Other fixes specific to floats will be easier to implement.
base/rational.jl
Outdated
Comment on lines
260
to
258
| a = trunc(x) | ||
| r = x-a | ||
| y = one(x) | ||
| r, a = modf(x) |
Member
There was a problem hiding this comment.
what's a case where the difference here matters?
Contributor
Author
There was a problem hiding this comment.
It doesn't matter. I just applied those changes without the fix for tiny x. One line vs two I guess. It wasn't a problem until now.
Member
There was a problem hiding this comment.
makes sense. Looks like there's no perf difference.
Contributor
Author
There was a problem hiding this comment.
I thought "more concise" but I understand modf does some checks we don't need at this point and in absolute terms it would be better to revert that change.
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.
Fixes #60768
tolignored whenTis not specified.xunless the giventolis significant enough to reduce the magnitude of its components, in which case rationalizefloat(x)instead.