Skip to content

Commit

Permalink
irrational sign() (#37949)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Feb 25, 2022
1 parent 76fc067 commit 9b8253c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ zero(::Type{<:AbstractIrrational}) = false
one(::AbstractIrrational) = true
one(::Type{<:AbstractIrrational}) = true

sign(x::AbstractIrrational) = ifelse(x < zero(x), -1.0, 1.0)

-(x::AbstractIrrational) = -Float64(x)
for op in Symbol[:+, :-, :*, :/, :^]
@eval $op(x::AbstractIrrational, y::AbstractIrrational) = $op(Float64(x),Float64(y))
Expand Down
2 changes: 2 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ end
@test isa(sign(2//3), Rational{Int})
@test isa(2//3 + 2//3im, Complex{Rational{Int}})
@test isa(sign(2//3 + 2//3im), ComplexF64)
@test sign(pi) === 1.0
@test sign(pi) === -sign(-pi)
@test sign(one(UInt)) == 1
@test sign(zero(UInt)) == 0

Expand Down

0 comments on commit 9b8253c

Please sign in to comment.