Skip to content

Commit

Permalink
Add ustrip() support to Base.TwicePrecision (#711)
Browse files Browse the repository at this point in the history
Fixes #709
  • Loading branch information
staticfloat authored Apr 16, 2024
1 parent c333efe commit 6bfc193
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ _colon(::Any, ::Any, start::T, step, stop::T) where {T} =
*(x::Base.TwicePrecision, y::Units) = Base.TwicePrecision(x.hi*y, x.lo*y)
*(x::Base.TwicePrecision, y::Quantity) = (x * ustrip(y)) * unit(y)
uconvert(y, x::Base.TwicePrecision) = Base.TwicePrecision(uconvert(y, x.hi), uconvert(y, x.lo))
ustrip(x::Base.TwicePrecision) = Base.TwicePrecision(ustrip(x.hi), ustrip(x.lo))
@inline upreferred(x::Base.TwicePrecision{T}) where T<:Number = x
@inline upreferred(x::Base.TwicePrecision{T}) where T<:AbstractQuantity =
uconvert(upreferred(unit(x)), x)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,10 @@ end
@test_throws ArgumentError range(step=1m, length=5)
end
end
@testset ">> broadcast ustrip" begin
@test ustrip.(1:0.1:1.0) == 1:0.1:1.0
@test ustrip.(1m:0.1m:1.0m) == 1:0.1:1.0
end
end
@testset "> Arrays" begin
@testset ">> Array multiplication" begin
Expand Down

0 comments on commit 6bfc193

Please sign in to comment.