Skip to content

Commit

Permalink
fix sign function for NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Feb 2, 2017
1 parent 7d91e3b commit 2fe9198
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ signbit(x::Real) = x < 0
Return zero if `x==0` and ``x/|x|`` otherwise (i.e., ±1 for real `x`).
"""
sign(x::Number) = x == 0 ? x/abs(oneunit(x)) : x/abs(x)
sign(x::Real) = ifelse(x < 0, oftype(one(x),-1), ifelse(x > 0, one(x), oftype(one(x),0)))
sign(x::Real) = ifelse(x < 0, oftype(one(x),-1), ifelse(x > 0, one(x), typeof(one(x))(x)))
sign(x::Unsigned) = ifelse(x > 0, one(x), oftype(one(x),0))
abs(x::Real) = ifelse(signbit(x), -x, x)

Expand Down

0 comments on commit 2fe9198

Please sign in to comment.