Make ranges not bugs
Author jw3126
9 Stars
Updated Last
1 Year Ago
Started In
October 2020


Stable Dev Build Status Build Status Coverage

Ever needed a range with startpoint 10, endpoint 121.7 and a step of 25? Well that is mathematically not possible, so you need to compromise. There are lots of options, you could relax the startpoint, endpoint or step. In the past doing this was annoying and prone to off-by-one-errors:

julia> Base.range(10, step=25, length=round(Int, (121.7-10)/25)); # is it correct??

RangeHelpers.jl aims to solve range construction headaches once and for all:

julia> using RangeHelpers: range

julia> using RangeHelpers

julia> range(start=10, stop=121.7, step=around(25)) # compromise on step

julia> range(start=10, stop=121.7, step=below(25))  # compromise step at most 25

julia> range(start=10, stop=above(121.7), step=25)  # exact step, but allow bigger endpoint

julia> anchorrange(42, start=around(10), step=25, stop=around(121.7)) # make sure 42 is on the grid

See the documentation for even more ways to make ranges.

Required Packages

No packages found.