@@ -575,8 +575,11 @@ norm_sqr(x::Union{T,Complex{T},Rational{T}}) where {T<:Integer} = abs2(float(x))
575575function generic_norm2 (x)
576576 maxabs = normInf (x)
577577 (ismissing (maxabs) || iszero (maxabs) || isinf (maxabs)) && return maxabs
578+ return _generic_norm2 (x, maxabs)
579+ end
580+
581+ function _generic_norm2 (x, maxabs:: T ) where {T}
578582 (v, s) = iterate (x):: Tuple
579- T = typeof (maxabs)
580583 if isfinite (length (x)* maxabs* maxabs) && ! iszero (maxabs* maxabs) # Scaling not necessary
581584 sum:: promote_type (Float64, T) = norm_sqr (v)
582585 for v in Iterators. rest (x, s)
@@ -601,10 +604,15 @@ function generic_normp(x, p)
601604 if p > 1 || p < - 1 # might need to rescale to avoid overflow
602605 maxabs = p > 1 ? normInf (x) : normMinusInf (x)
603606 (ismissing (maxabs) || iszero (maxabs) || isinf (maxabs)) && return maxabs
604- T = typeof ( maxabs)
607+ return _generic_normp (x, p, maxabs)
605608 else
606- T = typeof (float (norm (v)))
609+ # in this case, only the type of the last argument is used
610+ # there is no scaling involved
611+ return _generic_normp (x, p, float (norm (v)))
607612 end
613+ end
614+
615+ function _generic_normp (x, p, maxabs:: T ) where {T}
608616 spp:: promote_type (Float64, T) = p
609617 if - 1 <= p <= 1 || (isfinite (length (x)* maxabs^ spp) && ! iszero (maxabs^ spp)) # scaling not necessary
610618 sum:: promote_type (Float64, T) = norm (v)^ spp
0 commit comments