Looking at your note, I noticed this: * hypot(Inf,NaN) == hypot(NaN,Inf) == Inf*
That cannot be correct because *sqrt(x^2 + NaN^2) => sqrt(x^2 + NaN) =>
sqrt(NaN) => NaN*
On Saturday, March 26, 2016 at 3:23:32 PM UTC-4, feza wrote:
>
> Why is hypot1 preferred (in Base) over hypot2 ? To me it seems better to
> just return y in the one commented line
>
> function hypot2{T<:AbstractFloat}(x::T, y::T)
>
> x = abs(x)
>
> y = abs(y)
>
> if x < y
>
> x, y = y, x
>
> end
>
> if x == 0
>
> return y ## compare with below
>
> else
>
> r = y/x
>
> if isnan(r)
>
> isinf(x) && return x
>
> isinf(y) && return y
>
> return r
>
> end
>
> end
>
> x * sqrt(one(r)+r*r)
>
> end
>
>
>
> function hypot1{T<:AbstractFloat}(x::T, y::T)
>
> x = abs(x)
>
> y = abs(y)
>
> if x < y
>
> x, y = y, x
>
> end
>
> if x == 0
>
> r = y/one(x) # Why not just return y?
> else
>
> r = y/x
>
> if isnan(r)
>
> isinf(x) && return x
>
> isinf(y) && return y
>
> return r
>
> end
>
> end
>
> x * sqrt(one(r)+r*r)
>
> end
>
>
