Skip to content

Commit b23d668

Browse files
Fix p-norm for unitful quantities (#1291)
* fix p-norm for unitful quantities * set version to v1.9.9
1 parent b62e257 commit b23d668

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.9.8"
3+
version = "1.9.9"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/linalg.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ end
301301
$(Expr(:meta, :inline))
302302
scale = maxabs_nested(a)
303303

304-
scale==0 && return _init_zero(a)
304+
iszero(scale) && return _init_zero(a)
305305
p == 1 && return @inbounds scale * $expr_p1
306306
return @inbounds scale * ($expr)^(inv(p))
307307
end
@@ -328,7 +328,7 @@ end
328328
p == Inf && return mapreduce(norm, max, a) # no need for scaling
329329

330330
l = p==1 ? @inbounds($expr_p1) : @inbounds(($expr)^(inv(p)))
331-
0<l<Inf && return l
331+
zero(l) < l && isfinite(l) && return l
332332
return _norm_scaled(Size(a), a, p) # p != 0, 2, Inf
333333
end
334334
end

test/unitful.jl

+3
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ using Unitful
55
@test norm(SVector(1.0*u"m")) == 1.0*u"m"
66
# issue $1127
77
@test norm(SVector(0.0, 0.0)*u"nm") == 0.0*u"nm"
8+
9+
@test norm(SVector(1.0, 2.0)*u"m", 1) == 3.0*u"m"
10+
@test norm(SVector(0.0, 0.0)*u"nm", 1) == 0.0*u"nm"
811
end

0 commit comments

Comments
 (0)