Skip to content

Commit

Permalink
Mention integers in mod1 docstring (JuliaLang#41448)
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
2 people authored and johanmon committed Jul 5, 2021
1 parent f300dd3 commit 22e22c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -875,15 +875,24 @@ const ÷ = div
Modulus after flooring division, returning a value `r` such that `mod(r, y) == mod(x, y)`
in the range ``(0, y]`` for positive `y` and in the range ``[y,0)`` for negative `y`.
See also [`fld1`](@ref), [`fldmod1`](@ref).
With integer arguments and positive `y`, this is equal to `mod(x, 1:y)`, and hence natural
for 1-based indexing. By comparison, `mod(x, y) == mod(x, 0:y-1)` is natural for computations with
offsets or strides.
See also [`mod`](@ref), [`fld1`](@ref), [`fldmod1`](@ref).
# Examples
```jldoctest
julia> mod1(4, 2)
2
julia> mod1(4, 3)
1
julia> mod1.(-5:5, 3)'
1×11 adjoint(::Vector{Int64}) with eltype Int64:
1 2 3 1 2 3 1 2 3 1 2
julia> mod1.([-0.1, 0, 0.1, 1, 2, 2.9, 3, 3.1]', 3)
1×8 Matrix{Float64}:
2.9 3.0 0.1 1.0 2.0 2.9 3.0 0.1
```
"""
mod1(x::T, y::T) where {T<:Real} = (m = mod(x, y); ifelse(m == 0, y, m))
Expand Down
4 changes: 2 additions & 2 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,10 +1357,10 @@ See also [`mod1`](@ref).
# Examples
```jldoctest
julia> mod(0, Base.OneTo(3))
julia> mod(0, Base.OneTo(3)) # mod1(0, 3)
3
julia> mod(3, 0:2)
julia> mod(3, 0:2) # mod(3, 3)
0
```
Expand Down

0 comments on commit 22e22c4

Please sign in to comment.