JuliaLang/julia — pull request #6101 by stevengj (2014-03-10 20:31:31+00:00)
Title: type stability in all norm variants

Continuing where #6056 and #6057, this makes all the `norm` functions type stable, both internally and externally.

Previously, similar to #6056, `norm(x, p)` was not type stable, in the sense that the norm of an integer matrix or scalar would return different types for different `p`. It was also not internally type stable, in that the reduction loop would change the type of the accumulator variable if `typeof(zero(T)) != typeof(zero(T)+zero(T))`, similar to #6069.

Now, all matrix norms return a floating-point result, and accumulations are performed in at least double precision, similar to `vecnorm`. `norm(x::Number, p)` returns a value with the same type as `real(x)` or `abs(x)`, since adding the floating-point conversion there would have complicated the code to no useful purpose.