Actually I don't know if this is intended behavior or not for example in MATLAB hypot(NaN,Inf) and hypot(Inf,NaN) both give NaN
BUT http://en.cppreference.com/w/c/numeric/math/hypot specifies that even if one of the arugments is NaN hypot returns +Inf On Saturday, March 26, 2016 at 3:54:22 PM UTC-4, feza wrote: > > Good catch Jeffrey. I will file a bug report! > > On Saturday, March 26, 2016 at 3:50:31 PM UTC-4, Jeffrey Sarnoff wrote: >> >> 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 >>> >>> >>
