Skip to content

Commit 9b8253c

Browse files
authored
irrational sign() (#37949)
1 parent 76fc067 commit 9b8253c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/irrationals.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ zero(::Type{<:AbstractIrrational}) = false
153153
one(::AbstractIrrational) = true
154154
one(::Type{<:AbstractIrrational}) = true
155155

156+
sign(x::AbstractIrrational) = ifelse(x < zero(x), -1.0, 1.0)
157+
156158
-(x::AbstractIrrational) = -Float64(x)
157159
for op in Symbol[:+, :-, :*, :/, :^]
158160
@eval $op(x::AbstractIrrational, y::AbstractIrrational) = $op(Float64(x),Float64(y))

test/numbers.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ end
490490
@test isa(sign(2//3), Rational{Int})
491491
@test isa(2//3 + 2//3im, Complex{Rational{Int}})
492492
@test isa(sign(2//3 + 2//3im), ComplexF64)
493+
@test sign(pi) === 1.0
494+
@test sign(pi) === -sign(-pi)
493495
@test sign(one(UInt)) == 1
494496
@test sign(zero(UInt)) == 0
495497

0 commit comments

Comments
 (0)