Skip to content

Commit

Permalink
Fix zero(::Type{<:TwicePrecision}) for dimensionful quantities (#36113)
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock authored Jun 4, 2020
1 parent 095e92d commit 38238c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/twiceprecision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ big(x::TwicePrecision) = big(x.hi) + big(x.lo)

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

zero(::Type{TwicePrecision{T}}) where {T} = TwicePrecision{T}(0, 0)
function zero(::Type{TwicePrecision{T}}) where {T}
z = zero(T)
TwicePrecision{T}(z, z)
end

# Arithmetic

Expand Down
1 change: 1 addition & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ end
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x*2 # not a MethodError for convert
@test x.hi/2 === PhysQuantity{1}(2.0)
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x/2
@test zero(typeof(x)) === Base.TwicePrecision(PhysQuantity{1}(0.0))
end
@testset "ranges" begin
@test size(10:1:0) == (0,)
Expand Down

0 comments on commit 38238c8

Please sign in to comment.