From f6f3eaa36d8d1747b43dcadd326f412c1b48c865 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 25 Sep 2026 17:00:02 -0700 Subject: [PATCH 1/2] Support arbitrary `AbstractIrrational`s 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 --- src/Quadmath.jl | 2 +- test/runtests.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Quadmath.jl b/src/Quadmath.jl index ca5fed3..8c92568 100644 --- a/src/Quadmath.jl +++ b/src/Quadmath.jl @@ -465,7 +465,7 @@ end 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)) import Base.MPFR diff --git a/test/runtests.jl b/test/runtests.jl index 49c81ac..1bf8da5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -202,11 +202,18 @@ end @test parse(Float128,"3.0") == Float128(3.0) end +struct TwoPi <: AbstractIrrational +end +Base.BigFloat(::TwoPi; precision=precision(BigFloat)) = + setprecision(() -> 2 * big(π), BigFloat, precision) +Base.Float64(x::TwoPi) = Float64(big(x)) + @testset "irrationals" begin tiny = 2eps(Float128(1)) @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 end @testset "rationals" begin From d58fb5e873a598e5e0ad821b35a579c3c651662f Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 28 Sep 2026 12:47:59 -0700 Subject: [PATCH 2/2] Set precision in irrational method, test multiple precisions --- src/Quadmath.jl | 2 +- test/runtests.jl | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Quadmath.jl b/src/Quadmath.jl index 8c92568..0d2b8d7 100644 --- a/src/Quadmath.jl +++ b/src/Quadmath.jl @@ -465,7 +465,7 @@ end Float128(::Irrational{:π}) = reinterpret(Float128, 0x4000921fb54442d18469898cc51701b8) Float128(::Irrational{:ℯ}) = reinterpret(Float128, 0x40005bf0a8b1457695355fb8ac404e7a) -Float128(x::AbstractIrrational) = Float128(BigFloat(x)) +Float128(x::AbstractIrrational) = Float128(BigFloat(x; precision=128)) import Base.MPFR diff --git a/test/runtests.jl b/test/runtests.jl index 1bf8da5..4d60ead 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -210,10 +210,15 @@ Base.Float64(x::TwoPi) = Float64(big(x)) @testset "irrationals" begin tiny = 2eps(Float128(1)) - @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 + default = precision(BigFloat) + for prec in (default, 16) + setprecision(BigFloat, prec) + @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 + end + setprecision(default) end @testset "rationals" begin