Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jun 10, 2021
1 parent 2b84b9f commit 7b062ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
59 changes: 11 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,24 @@ 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
range(10, length=ceil(Int, (121.7-10)/25), stop=121.7);
julia> Base.range(10, step=25, length=round(Int, (121.7-10)/25)); # is it correct??
```
[RangeHelpers.jl](https://github.com/jw3126/RangeHelpers.jl) aims to solve this and related range constructions once and for all:
[RangeHelpers.jl](https://github.com/jw3126/RangeHelpers.jl) aims to solve range construction headaches once and for all:
```julia
julia> import RangeHelpers as RH
julia> using RangeHelpers: range

julia> using RangeHelpers

julia> RH.range(start=10, stop=121.7, step=RH.around(25)) # compromise on step
julia> range(start=10, stop=121.7, step=around(25)) # compromise on step
10.0:27.925:121.7

julia> RH.range(start=10, stop=121.7, step=RH.below(25)) # compromise step at most 25
julia> range(start=10, stop=121.7, step=below(25)) # compromise step at most 25
10.0:22.34:121.7

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

# More examples
```julia
julia> using RangeHelpers

julia> using RangeHelpers: range

julia> range(start=1, stop=3, length=3)
1.0:1.0:3.0

julia> range(start=1, stop=3.1, step=around(1))
1.0:1.05:3.1

julia> range(start=1, stop=around(3.1), step=1)
1:1:3

julia> range(start=1, stop=above(3.1), step=1)
1:1:4

julia> range(start=1, stop=above(3.0), step=1)
1:1:3

julia> range(start=around(0.9), stop=3.0, step=1)
1.0:1.0:3.0

julia> range(start=strictbelow(1.0), stop=3.0, step=1)
0.0:1.0:3.0

julia> r = 1.0:0.5:3.0
1.0:0.5:3.0

julia> prolong(r, stop=around(4))
1.0:0.5:4.0

julia> prolong(r, pre=1)
0.5:0.5:3.0

julia> prolong(r, pre=1, post=2)
0.5:0.5:4.0

julia> prolong(r, start=below(0.4), stop=around(4.1))
0.0:0.5:4.0
julia> anchorrange(42, start=around(10), step=25, stop=around(121.7)) # make sure 42 is on the grid
17.0:25.0:117.0
```
See [the documentation](https://jw3126.github.io/RangeHelpers.jl/dev/) for even more ways to make ranges.
1 change: 1 addition & 0 deletions src/RangeHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export binwalls, bincenters
@doc let path = joinpath(dirname(@__DIR__), "README.md")
include_dependency(path)
replace(read(path, String), "```julia" => "```jldoctest README")
#read(path, String)
end RangeHelpers

################################################################################
Expand Down

2 comments on commit 7b062ef

@jw3126
Copy link
Owner Author

@jw3126 jw3126 commented on 7b062ef Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/38394

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.4 -m "<description of version>" 7b062ef73f5751550d2007d510ef9b80a33ae006
git push origin v0.1.4

Also, note the warning: Version 0.1.4 skips over 0.1.3
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.