Skip to content

Commit

Permalink
Merge b5e50eb into f48af99
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Nov 23, 2019
2 parents f48af99 + b5e50eb commit 92a98cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Measurements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ include("math.jl")
include("show.jl")
include("parsing.jl")
include("plot-recipes.jl")
include("misc.jl")

end # module
11 changes: 11 additions & 0 deletions src/misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Base: Broadcast.DefaultArrayStyle, AbstractUnitRange

_broadcasted(style, f, x, r::AbstractRange) = invoke(Base.broadcasted, Tuple{typeof(style),typeof(f),Any,typeof(r)}, style, f, x, r)
_broadcasted(style, f, r::AbstractRange, x) = invoke(Base.broadcasted, Tuple{typeof(style),typeof(f),typeof(r),Any}, style, f, r, x)

for f in (+, -, *, /, \), R in (AbstractRange, AbstractUnitRange, StepRangeLen)
@eval begin
Base.Broadcast.broadcasted(style::DefaultArrayStyle{1}, ::typeof($f), x::Measurement, r::$R) = _broadcasted(style, $f, x, r)
Base.Broadcast.broadcasted(style::DefaultArrayStyle{1}, ::typeof($f), r::$R, x::Measurement) = _broadcasted(style, $f, r, x)
end
end
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,11 @@ end
@testset "Plot recipes" begin
include("plots.jl")
end

@testset begin "Broadcasting with ranges"
m = 2 ± 1
@test m .+ (1:6) isa Vector{<:Measurement}
@test m .* (1:2:6) isa Vector{<:Measurement}
@test (1:.1:6) .- m isa Vector{<:Measurement}
@test m ./ (1:6.0) isa Vector{<:Measurement}
end

0 comments on commit 92a98cd

Please sign in to comment.