Skip to content

Sum of ranges in a set-like contextΒ #33577

@rapus95

Description

@rapus95

Right now we have

julia> r1=range(-2, 4, step=0.5)
-2.0:0.5:4.0

julia> r2 = range(3, 9, step=0.5)
3.0:0.5:9.0

julia> r1+r2
1.0:1.0:13.0

julia> r1.+r2
1.0:1.0:13.0

But I wonder whether it would be worthwhile to make + the set addition (aka r1+r2 = {a+b | a\in r1, b\in r2})
and thus the step wouldn't change.
Implementation:

julia> function newadd(a::AbstractRange, b::AbstractRange)
    step(a)==step(b) || error("have to have same step")
    return range(first(a)+first(b), last(a)+last(b), step=step(a))
end
newadd (generic function with 1 method)

julia> newadd(r1,r2)
1.0:0.5:13.0 #step ist now 0.5 instead of 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsrangesEverything AbstractRange

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions