Conversation
The fallback method had been using `Irrational{T}`, but irrational
values needn't be `Irrational`s, so we can just use `AbstractIrrational`
for that method instead.
Fixes issue 100
stevengj
reviewed
Sep 26, 2026
| Float128(::Irrational{:π}) = reinterpret(Float128, 0x4000921fb54442d18469898cc51701b8) | ||
| Float128(::Irrational{:ℯ}) = reinterpret(Float128, 0x40005bf0a8b1457695355fb8ac404e7a) | ||
| Float128(x::Irrational{T}) where {T} = Float128(BigFloat(x)) | ||
| Float128(x::AbstractIrrational) = Float128(BigFloat(x)) |
Member
There was a problem hiding this comment.
Shouldn't we specify the precision here? (The default BigFloat precision of 256 is more than what is required, but the user might have called setprecision to a lower precision.)
Suggested change
| Float128(x::AbstractIrrational) = Float128(BigFloat(x)) | |
| Float128(x::AbstractIrrational) = Float128(BigFloat(x, precision=128)) |
(technically I guess you could use precision=113, but it seems sensible to have a few guard bits and I doubt there is much of a performance price to round up to the next power of 2)
stevengj
reviewed
Sep 26, 2026
| @test abs(cos(Float128(pi)) + 1) < tiny | ||
| @test abs(log(Float128(ℯ)) - 1) < tiny | ||
| @test abs((2*Float128(MathConstants.golden) - 1)^2 - 5) < 5 * tiny | ||
| @test abs(cos(Float128(TwoPi())) - 1) < tiny |
Member
There was a problem hiding this comment.
Would be good to test the above issue by surrounding the tests with setprecision(16) do ... end
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.
The fallback method had been using
Irrational{T}, but irrational values needn't beIrrationals, so we can just useAbstractIrrationalfor that method instead.Fixes #100