Skip to content

Commit

Permalink
Add inv(::Missing) (JuliaLang#31451)
Browse files Browse the repository at this point in the history
* add inv(::Missing)

* update docstring for inv method
  • Loading branch information
narendrakpatel authored and ararslan committed Mar 26, 2019
1 parent a90629a commit 8649af9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------

Expand Down
2 changes: 1 addition & 1 deletion base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8649af9

Please sign in to comment.