Skip to content

Commit

Permalink
hypot behaves like L2-norm, adjust the docstring to reflect this (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano authored and simonbyrne committed May 28, 2019
1 parent 852d084 commit 93972d1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ sqrt(x::Real) = sqrt(float(x))
"""
hypot(x, y)
Compute the hypotenuse ``\\sqrt{x^2+y^2}`` avoiding overflow and underflow.
Compute the hypotenuse ``\\sqrt{|x|^2+|y|^2}`` avoiding overflow and underflow.
# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
Expand All @@ -535,6 +535,9 @@ ERROR: DomainError with -2.914184810805068e18:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[...]
julia> hypot(3, 4im)
5.0
```
"""
hypot(x::Number, y::Number) = hypot(promote(x, y)...)
Expand Down Expand Up @@ -566,7 +569,16 @@ end
"""
hypot(x...)
Compute the hypotenuse ``\\sqrt{\\sum x_i^2}`` avoiding overflow and underflow.
Compute the hypotenuse ``\\sqrt{\\sum |x_i|^2}`` avoiding overflow and underflow.
# Examples
```jldoctest
julia> hypot(-5.7)
5.7
julia> hypot(3, 4im, 12.0)
13.0
```
"""
hypot(x::Number...) = sqrt(sum(abs2(y) for y in x))

Expand Down

0 comments on commit 93972d1

Please sign in to comment.