Skip to content

Commit

Permalink
expand min/max with missing to all types (#25403)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jan 5, 2018
1 parent 9dd18b1 commit f41a8f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@ for f in (:(Base.zero), :(Base.one), :(Base.oneunit))
end

# Binary operators/functions
for f in (:(+), :(-), :(*), :(/), :(^),
:(div), :(mod), :(fld), :(rem), :(min), :(max))
for f in (:(+), :(-), :(*), :(/), :(^), :(div), :(mod), :(fld), :(rem))
@eval begin
# Scalar with missing
($f)(::Missing, ::Missing) = missing
($f)(d::Missing, x::Number) = missing
($f)(d::Number, x::Missing) = missing
($f)(::Missing, ::Number) = missing
($f)(::Number, ::Missing) = missing
end
end

min(::Missing, ::Missing) = missing
min(::Missing, ::Any) = missing
min(::Any, ::Missing) = missing
max(::Missing, ::Missing) = missing
max(::Missing, ::Any) = missing
max(::Any, ::Missing) = missing

# Rounding and related functions
for f in (:(ceil), :(floor), :(round), :(trunc))
@eval begin
Expand Down
9 changes: 9 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ end
@test ismissing(f(1, missing))
@test ismissing(f(missing, 1))
end

@test ismissing(min(missing, missing))
@test ismissing(max(missing, missing))
for f in [min, max]
for arg in ["", "a", 1, -1.0, [2]]
@test ismissing(f(missing, arg))
@test ismissing(f(arg, missing))
end
end
end

@testset "bit operators" begin
Expand Down

0 comments on commit f41a8f8

Please sign in to comment.