Skip to content

Commit 38238c8

Browse files
authored
Fix zero(::Type{<:TwicePrecision}) for dimensionful quantities (#36113)
1 parent 095e92d commit 38238c8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

base/twiceprecision.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ big(x::TwicePrecision) = big(x.hi) + big(x.lo)
257257

258258
-(x::TwicePrecision) = TwicePrecision(-x.hi, -x.lo)
259259

260-
zero(::Type{TwicePrecision{T}}) where {T} = TwicePrecision{T}(0, 0)
260+
function zero(::Type{TwicePrecision{T}}) where {T}
261+
z = zero(T)
262+
TwicePrecision{T}(z, z)
263+
end
261264

262265
# Arithmetic
263266

test/ranges.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ end
193193
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x*2 # not a MethodError for convert
194194
@test x.hi/2 === PhysQuantity{1}(2.0)
195195
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x/2
196+
@test zero(typeof(x)) === Base.TwicePrecision(PhysQuantity{1}(0.0))
196197
end
197198
@testset "ranges" begin
198199
@test size(10:1:0) == (0,)

0 commit comments

Comments
 (0)