Skip to content

Commit

Permalink
typeassert Bool for ifelse
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Aug 16, 2022
1 parent 33378dc commit e87e072
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ julia> max(2, 5, 1)
5
```
"""
max(x, y) = ifelse(isless(y, x), x, y)
max(x, y) = ifelse(isless(y, x)::Bool, x, y)

"""
min(x, y, ...)
Expand Down
14 changes: 7 additions & 7 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,15 @@ prod(a; kw...) = mapreduce(identity, mul_prod, a; kw...)
_fast(::typeof(min),x,y) = min(x,y)
_fast(::typeof(max),x,y) = max(x,y)
function _fast(::typeof(max), x::AbstractFloat, y::AbstractFloat)
ifelse(isnan(x),
ifelse(isnan(x)::Bool,
x,
ifelse(x > y, x, y))
ifelse((x > y)::Bool, x, y))
end

function _fast(::typeof(min),x::AbstractFloat, y::AbstractFloat)
ifelse(isnan(x),
ifelse(isnan(x)::Bool,
x,
ifelse(x < y, x, y))
ifelse((x < y)::Bool, x, y))
end

isbadzero(::typeof(max), x::AbstractFloat) = (x == zero(x)) & signbit(x)
Expand Down Expand Up @@ -859,9 +859,9 @@ ExtremaMap(::Type{T}) where {T} = ExtremaMap{Type{T}}(T)
# optimization for IEEEFloat
function _extrema_rf(x::NTuple{2,T}, y::NTuple{2,T}) where {T<:IEEEFloat}
(x1, x2), (y1, y2) = x, y
anynan = isnan(x1)|isnan(y1)
z1 = ifelse(anynan, x1-y1, ifelse(signbit(x1-y1), x1, y1))
z2 = ifelse(anynan, x1-y1, ifelse(signbit(x2-y2), y2, x2))
anynan::Bool = isnan(x1)|isnan(y1)
z1 = ifelse(anynan, x1-y1, ifelse(signbit(x1-y1)::Bool, x1, y1))
z2 = ifelse(anynan, x1-y1, ifelse(signbit(x2-y2)::Bool, y2, x2))
z1, z2
end

Expand Down

0 comments on commit e87e072

Please sign in to comment.