Skip to content

Commit

Permalink
Fix rem/mod doc (#21223)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao authored and ararslan committed Mar 29, 2017
1 parent 4fe28fb commit d266f92
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,24 @@ for to in BitInteger_types, from in (BitInteger_types..., Bool)
end
end

"""
rem(x::Integer, T::Type{<:Integer})
mod(x::Integer, T::Type{<:Integer})
%(x::Integer, T::Type{<:Integer})
Find `y::T` such that `x` ≡ `y` (mod n), where n is the number of integers representable
in `T`, and `y` is an integer in `[typemin(T),typemax(T)]`.
```jldoctest
julia> 129 % Int8
-127
```
"""
function rem(x::Integer, T::Type) end, function mod(x::Integer, T::Type) end
# @doc isn't available when running in Core at this point.
# Tuple syntax for documention two function signatures at the same time
# doesn't work either at this point.
isdefined(Main, :Base) && for fname in (:mod, :rem)
@eval @doc """

This comment has been minimized.

Copy link
@martinholters

martinholters Apr 21, 2017

Member

This breaks the ability to do include("coreimg.jl") (useful e.g. when hacking inference.jl). Would @eval Main.Base @doc ... do?

This comment has been minimized.

Copy link
@yuyichao

yuyichao Apr 21, 2017

Author Contributor

That should be OK as long as it doesn't break bootstrap.

This comment has been minimized.

Copy link
@vtjnash

vtjnash Apr 21, 2017

Member

Maybe do module_name(current_module()) == :Base instead?

This comment has been minimized.

Copy link
@yuyichao

yuyichao Apr 21, 2017

Author Contributor

Could be. Assuming they are defined. I was just copying from other places that does this check, which uses this version probably because it relies less on functions being defined...

This comment has been minimized.

Copy link
@martinholters

martinholters Apr 26, 2017

Member

Has to be === instead of ==, but looks good otherwise.

rem(x::Integer, T::Type{<:Integer})
mod(x::Integer, T::Type{<:Integer})
%(x::Integer, T::Type{<:Integer})
Find `y::T` such that `x` ≡ `y` (mod n), where n is the number of integers representable
in `T`, and `y` is an integer in `[typemin(T),typemax(T)]`.
```jldoctest
julia> 129 % Int8
-127
```
""" -> $fname(x::Integer, T::Type{<:Integer})
end

rem{T<:Integer}(x::T, ::Type{T}) = x
rem(x::Integer, ::Type{Bool}) = ((x & 1) != 0)
Expand Down

0 comments on commit d266f92

Please sign in to comment.