From f9c7716f7528992d4c3ed4569c36048bcdb96df8 Mon Sep 17 00:00:00 2001 From: Arnav Sood Date: Fri, 15 Feb 2019 12:11:35 -0800 Subject: [PATCH] define fallback `inv(x::AbstractIrrational)` (#31068) close #30882 --- base/irrationals.jl | 3 +++ test/numbers.jl | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/base/irrationals.jl b/base/irrationals.jl index 8249dc07ce773..1c3557cc5581c 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -185,3 +185,6 @@ function alignment(io::IO, x::AbstractIrrational) m === nothing ? (length(sprint(show, x, context=ctx, sizehint=0)), 0) : (length(m.captures[1]), length(m.captures[2])) end + +# inv +inv(x::AbstractIrrational) = 1/x diff --git a/test/numbers.jl b/test/numbers.jl index 952cf67c36d03..d7a22b892edd3 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1038,6 +1038,10 @@ end end end +@testset "Irrational Inverses, Issue #30882" begin + @test @inferred(inv(π)) ≈ 0.3183098861837907 +end + @testset "Irrationals compared with Rationals and Floats" begin @test Float64(pi,RoundDown) < pi @test Float64(pi,RoundUp) > pi