Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7387, operations between ranges and non-real numbers #7425

Merged
merged 1 commit into from
Jul 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
8 changes: 8 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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