Skip to content

Commit

Permalink
define fallback inv(x::AbstractIrrational) (JuliaLang#31068)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnav Sood authored and StefanKarpinski committed Feb 15, 2019
1 parent e62b492 commit f9c7716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9c7716

Please sign in to comment.