Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22e22c4

Browse files
mcabbottvtjnash
authored andcommittedJul 5, 2021
Mention integers in mod1 docstring (JuliaLang#41448)
Co-authored-by: Jameson Nash <[email protected]>
1 parent f300dd3 commit 22e22c4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎base/operators.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,15 +875,24 @@ const ÷ = div
875875
Modulus after flooring division, returning a value `r` such that `mod(r, y) == mod(x, y)`
876876
in the range ``(0, y]`` for positive `y` and in the range ``[y,0)`` for negative `y`.
877877
878-
See also [`fld1`](@ref), [`fldmod1`](@ref).
878+
With integer arguments and positive `y`, this is equal to `mod(x, 1:y)`, and hence natural
879+
for 1-based indexing. By comparison, `mod(x, y) == mod(x, 0:y-1)` is natural for computations with
880+
offsets or strides.
881+
882+
See also [`mod`](@ref), [`fld1`](@ref), [`fldmod1`](@ref).
879883
880884
# Examples
881885
```jldoctest
882886
julia> mod1(4, 2)
883887
2
884888
885-
julia> mod1(4, 3)
886-
1
889+
julia> mod1.(-5:5, 3)'
890+
1×11 adjoint(::Vector{Int64}) with eltype Int64:
891+
1 2 3 1 2 3 1 2 3 1 2
892+
893+
julia> mod1.([-0.1, 0, 0.1, 1, 2, 2.9, 3, 3.1]', 3)
894+
1×8 Matrix{Float64}:
895+
2.9 3.0 0.1 1.0 2.0 2.9 3.0 0.1
887896
```
888897
"""
889898
mod1(x::T, y::T) where {T<:Real} = (m = mod(x, y); ifelse(m == 0, y, m))

‎base/range.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,10 @@ See also [`mod1`](@ref).
13571357
13581358
# Examples
13591359
```jldoctest
1360-
julia> mod(0, Base.OneTo(3))
1360+
julia> mod(0, Base.OneTo(3)) # mod1(0, 3)
13611361
3
13621362
1363-
julia> mod(3, 0:2)
1363+
julia> mod(3, 0:2) # mod(3, 3)
13641364
0
13651365
```
13661366

0 commit comments

Comments
 (0)
Please sign in to comment.