Skip to content

Commit

Permalink
Update math.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Dec 20, 2021
1 parent f0c46b3 commit 7d5713d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,16 @@ end
atan(y::Real, x::Real) = atan(promote(float(y),float(x))...)
atan(y::T, x::T) where {T<:AbstractFloat} = Base.no_op_err("atan", T)

max(x::T, y::T) where {T<:AbstractFloat} = ifelse((y > x) | (signbit(y) < signbit(x)),
ifelse(isnan(x), x, y), ifelse(isnan(y), y, x))
_isless(x::T, y::T) where {T<:AbstractFloat} = (x < y) || (signbit(x) > signbit(y))
min(x::T, y::T) where {T<:AbstractFloat} = isnan(x) || ~isnan(y) && _isless(x, y) ? x : y
max(x::T, y::T) where {T<:AbstractFloat} = isnan(x) || ~isnan(y) && _isless(y, x) ? x : y
minmax(x::T, y::T) where {T<:AbstractFloat} = min(x, y), max(x, y)

_isless(x::T, y::T) where {T<:Union{Float32,Float64}} = signbit(x - y)
min(x::T, y::T) where {T<:Union{Float32,Float64}} = ifelse(isnan(x) | ~isnan(y) & _isless(x, y), x, y)
max(x::T, y::T) where {T<:Union{Float32,Float64}} = ifelse(isnan(x) | ~isnan(y) & _isless(y, x), x, y)

min(x::T, y::T) where {T<:AbstractFloat} = ifelse((y < x) | (signbit(y) > signbit(x)),
ifelse(isnan(x), x, y), ifelse(isnan(y), y, x))

minmax(x::T, y::T) where {T<:AbstractFloat} =
ifelse(isnan(x) | isnan(y), ifelse(isnan(x), (x,x), (y,y)),
ifelse((y > x) | (signbit(x) > signbit(y)), (x,y), (y,x)))

_isless(x::Float16, y::Float16) = _isless(widen(x), widen(y))

"""
ldexp(x, n)
Expand Down

0 comments on commit 7d5713d

Please sign in to comment.