diff --git a/base/range.jl b/base/range.jl index 989b1741ceb80..08b7220a92f3f 100644 --- a/base/range.jl +++ b/base/range.jl @@ -458,7 +458,16 @@ convert{T}(::Type{FloatRange{T}}, r::OrdinalRange) = # +/- of ranges is defined in operators.jl (to be able to use @eval etc.) -## non-linear operations on ranges ## +## non-linear operations on ranges and fallbacks for non-real numbers ## + +.+(x::Number, r::Range) = [ x+y for y=r ] +.+(r::Range, y::Number) = [ x+y for x=r ] + +.-(x::Number, r::Range) = [ x-y for y=r ] +.-(r::Range, y::Number) = [ x-y for x=r ] + +.*(x::Number, r::Range) = [ x*y for y=r ] +.*(r::Range, y::Number) = [ x*y for x=r ] ./(x::Number, r::Range) = [ x/y for y=r ] ./(r::Range, y::Number) = [ x/y for x=r ] diff --git a/test/ranges.jl b/test/ranges.jl index 8c5aca4128bdb..45c2114ea6576 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -325,3 +325,11 @@ r = linrange(0.25,0.25,1) #issue #7484 r7484 = 0.1:0.1:1 @test [reverse(r7484)] == reverse([r7484]) + +# issue #7387 +for r in (0:1, 0.0:1.0) + @test r+im == [r]+im + @test r-im == [r]-im + @test r*im == [r]*im + @test r/im == [r]/im +end