diff --git a/base/operators.jl b/base/operators.jl index 3292ab8f7abe6..00211ea56e76b 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -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)) diff --git a/base/range.jl b/base/range.jl index 37b2da7a3bb4c..2d97239357d76 100644 --- a/base/range.jl +++ b/base/range.jl @@ -1288,10 +1288,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 ```