diff --git a/src/Quadmath.jl b/src/Quadmath.jl index ca5fed3..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::Irrational{T}) where {T} = 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 49c81ac..4d60ead 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -202,11 +202,23 @@ 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 + 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