Error when asking for sign of positive Irrational

This is an error

julia> sign(π)
ERROR: InexactError: Bool(-1)
 [1] Bool
   @ ./float.jl:158 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] oftype(x::Bool, y::Int64)
   @ Base ./essentials.jl:396
 [4] sign(x::Irrational{:π})
   @ Base ./number.jl:162
 [5] top-level scope
   @ REPL[1]:1

but this is not

julia> sign(-π)

because here (in base/number.jl)

sign(x::Real) = ifelse(x < zero(x), oftype(one(x),-1), ifelse(x > zero(x), one(x), typeof(one(x))(x)))

Is this because one(π) == true and it’s trying to cast -1 to a Bool?

1 Like
1 Like

Thanks, hopefully this can be merged.

Today, we have started observing more irrational behavior:

πᵤₜᵢₙ isa Irrational
1 Like