diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index a730e213017a3..4f0b404bafe89 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -469,25 +469,25 @@ For numbers, return ``\\left( |x|^p \\right)^{1/p}``. # Examples ```jldoctest julia> norm(2, 1) -2 +2.0 julia> norm(-2, 1) -2 +2.0 julia> norm(2, 2) -2 +2.0 julia> norm(-2, 2) -2 +2.0 julia> norm(2, Inf) -2 +2.0 julia> norm(-2, Inf) -2 +2.0 ``` """ -@inline norm(x::Number, p::Real=2) = p == 0 ? (x==0 ? zero(abs(x)) : oneunit(abs(x))) : abs(x) +@inline norm(x::Number, p::Real=2) = p == 0 ? (x==0 ? zero(abs(float(x))) : oneunit(abs(float(x)))) : abs(float(x)) norm(::Missing, p::Real=2) = missing # special cases of opnorm diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index cff5aefff6a8f..2146fb5112f5e 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -225,6 +225,11 @@ end end end +@testset "Issue #30466" begin + @test norm([typemin(Int), typemin(Int)], Inf) == -float(typemin(Int)) + @test norm([typemin(Int), typemin(Int)], 1) == -2float(typemin(Int)) +end + @testset "potential overflow in normalize!" begin δ = inv(prevfloat(typemax(Float64))) v = [δ, -δ] diff --git a/test/testhelpers/Quaternions.jl b/test/testhelpers/Quaternions.jl index 0920b9dea00c6..280965f3a70e1 100644 --- a/test/testhelpers/Quaternions.jl +++ b/test/testhelpers/Quaternions.jl @@ -12,6 +12,7 @@ struct Quaternion{T<:Real} <: Number end Quaternion(s::Real, v1::Real, v2::Real, v3::Real) = Quaternion(promote(s, v1, v2, v3)...) Base.abs2(q::Quaternion) = q.s*q.s + q.v1*q.v1 + q.v2*q.v2 + q.v3*q.v3 +Base.float(z::Quaternion{T}) where T = Quaternion(float(z.s), float(z.v1), float(z.v2), float(z.v3)) Base.abs(q::Quaternion) = sqrt(abs2(q)) Base.real(::Type{Quaternion{T}}) where {T} = T Base.conj(q::Quaternion) = Quaternion(q.s, -q.v1, -q.v2, -q.v3)