diff --git a/NEWS.md b/NEWS.md index 6ff0c232da3fa..012e6747ec3a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,8 @@ New language features `findall`, `findfirst`, `argmin`/`argmax` and `findmin`/`findmax` to work with these objects, returning the index of matching non-missing elements in the parent ([#31008]). + * `inv(::Missing)` has now been added and returns `missing` ([#31408]). + Multi-threading changes ----------------------- diff --git a/base/missing.jl b/base/missing.jl index 670a60d987ef7..e8db30d7c2f43 100644 --- a/base/missing.jl +++ b/base/missing.jl @@ -79,7 +79,7 @@ for f in (:(!), :(~), :(+), :(-), :(zero), :(one), :(oneunit), :(isinteger), :(isreal), :(isnan), :(iszero), :(transpose), :(adjoint), :(float), :(conj), :(abs), :(abs2), :(iseven), :(ispow2), - :(real), :(imag), :(sign)) + :(real), :(imag), :(sign), :(inv)) @eval ($f)(::Missing) = missing end for f in (:(Base.zero), :(Base.one), :(Base.oneunit)) diff --git a/base/number.jl b/base/number.jl index 4a4b001b2a79f..7ec3f7425daf0 100644 --- a/base/number.jl +++ b/base/number.jl @@ -216,6 +216,9 @@ julia> inv(1 + 2im) * (1 + 2im) julia> inv(2//3) 3//2 ``` + +!!! compat "Julia 1.2" + `inv(::Missing)` requires at least Julia 1.2. """ inv(x::Number) = one(x)/x diff --git a/test/missing.jl b/test/missing.jl index d626c4222bd83..971f3a5d114aa 100644 --- a/test/missing.jl +++ b/test/missing.jl @@ -156,7 +156,7 @@ Base.one(::Type{Unit}) = 1 identity, zero, one, oneunit, iseven, isodd, ispow2, isfinite, isinf, isnan, iszero, - isinteger, isreal, transpose, adjoint, float] + isinteger, isreal, transpose, adjoint, float, inv] # All elementary functions return missing when evaluating missing for f in elementary_functions