Skip to content

Commit 5cdfd21

Browse files
committedOct 15, 2014
integer trunction: use n % T instead of mod(n, T).
1 parent 2ee9c15 commit 5cdfd21

10 files changed

+29
-28
lines changed
 

‎base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function dlm_parse{T,D}(dbuff::T, eol::D, dlm::D, qchar::D, cchar::D, ign_adj_dl
338338
all_ascii = (D <: Uint8) || (isascii(eol) && isascii(dlm) && (!allow_quote || isascii(qchar)) && (!allow_comments || isascii(cchar)))
339339
(T <: UTF8String) && all_ascii && (return dlm_parse(dbuff.data, uint8(eol), uint8(dlm), uint8(qchar), uint8(cchar), ign_adj_dlm, allow_quote, allow_comments, skipstart, skipblanks, dh))
340340
ncols = nrows = col = 0
341-
is_default_dlm = (dlm == mod(invalid_dlm, D))
341+
is_default_dlm = (dlm == invalid_dlm % D)
342342
error_str = ""
343343
# 0: begin field, 1: quoted field, 2: unquoted field, 3: second quote (could either be end of field or escape character), 4: comment, 5: skipstart
344344
state = (skipstart > 0) ? 5 : 0

‎base/deprecated.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ const None = Union()
196196
@deprecate Dict{V}(ks::Tuple, vs::(V...)) Dict{Any,V}(zip(ks, vs))
197197
@deprecate Dict(ks, vs) Dict{Any,Any}(zip(ks, vs))
198198

199-
@deprecate itrunc{T<:Integer}(::Type{T}, n::Integer) mod(n, T)
199+
@deprecate itrunc{T<:Integer}(::Type{T}, n::Integer) (n % T)

‎base/hashing.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function hash_64_32(n::Uint64)
2929
a = a $ a >> 11
3030
a = a + a << 6
3131
a = a $ a >> 22
32-
return mod(a, Uint32)
32+
return a % Uint32
3333
end
3434

3535
function hash_32_32(n::Uint32)

‎base/int.jl

+13-12
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,29 @@ for to in tuple(IntTypes...,Char), from in tuple(IntTypes...,Char,Bool)
155155
else
156156
@eval convert(::Type{$to}, x::($from)) = box($to,checked_trunc_uint($to,unbox($from,x)))
157157
end
158-
@eval mod(x::($from), ::Type{$to}) = box($to,trunc_int($to,unbox($from,x)))
158+
@eval rem(x::($from), ::Type{$to}) = box($to,trunc_int($to,unbox($from,x)))
159159
elseif from.size < to.size || from === Bool
160160
if issubtype(from, Signed)
161161
@eval convert(::Type{$to}, x::($from)) = box($to,sext_int($to,unbox($from,x)))
162162
else
163163
@eval convert(::Type{$to}, x::($from)) = box($to,zext_int($to,unbox($from,x)))
164164
end
165-
@eval mod(x::($from), ::Type{$to}) = convert($to,x)
165+
@eval rem(x::($from), ::Type{$to}) = convert($to,x)
166166
else
167167
if !(issubtype(from,Signed) === issubtype(to,Signed))
168168
# raise InexactError if x's top bit is set
169169
@eval convert(::Type{$to}, x::($from)) = box($to,check_top_bit(unbox($from,x)))
170170
else
171171
@eval convert(::Type{$to}, x::($from)) = box($to,unbox($from,x))
172172
end
173-
@eval mod(x::($from), ::Type{$to}) = box($to,unbox($from,x))
173+
@eval rem(x::($from), ::Type{$to}) = box($to,unbox($from,x))
174174
end
175175
end
176176
end
177177

178-
mod{T<:Integer}(x::T, ::Type{T}) = x
179-
mod(x::Integer, ::Type{Bool}) = ((x&1)!=0)
178+
rem{T<:Integer}(x::T, ::Type{T}) = x
179+
rem(x::Integer, ::Type{Bool}) = ((x&1)!=0)
180+
mod{T<:Integer}(x::Integer, ::Type{T}) = rem(x, T)
180181

181182
for to in (Int8, Int16, Int32, Int64)
182183
@eval begin
@@ -240,7 +241,7 @@ int64(x) = convert(Int64,x)
240241
int128(x) = convert(Int128,x)
241242

242243
uint8(x) = convert(Uint8,x)
243-
uint8(x::Integer) = mod(x,Uint8)
244+
uint8(x::Integer) = x % Uint8
244245
uint8(x::Int8) = box(Uint8,unbox(Int8,x))
245246
uint8(x::Bool) = convert(Uint8,x)
246247

@@ -418,8 +419,8 @@ if WORD_SIZE==32
418419
end
419420

420421
function *(u::Int128, v::Int128)
421-
u0 = mod(u,Uint64); u1 = int64(u>>64)
422-
v0 = mod(v,Uint64); v1 = int64(v>>64)
422+
u0 = u % Uint64; u1 = int64(u>>64)
423+
v0 = v % Uint64; v1 = int64(v>>64)
423424
lolo = widemul(u0, v0)
424425
lohi = widemul(reinterpret(Int64,u0), v1)
425426
hilo = widemul(u1, reinterpret(Int64,v0))
@@ -429,8 +430,8 @@ if WORD_SIZE==32
429430
end
430431

431432
function *(u::Uint128, v::Uint128)
432-
u0 = mod(u,Uint64); u1 = int64(u>>64)
433-
v0 = mod(v,Uint64); v1 = int64(v>>64)
433+
u0 = u % Uint64; u1 = int64(u>>64)
434+
v0 = v % Uint64; v1 = int64(v>>64)
434435
lolo = widemul(u0, v0)
435436
lohi = widemul(u0, v1)
436437
hilo = widemul(u1, v0)
@@ -497,7 +498,7 @@ for T in (Int8,Uint8)
497498
@eval function checked_mul(x::$T, y::$T)
498499
xy = widemul(x,y)
499500
(typemin($T) <= xy <= typemax($T)) || throw(OverflowError())
500-
return mod(xy,$T)
501+
return xy % $T
501502
end
502503
end
503504

@@ -506,7 +507,7 @@ for T in (Int64,Uint64)
506507
@eval function checked_mul(x::$T, y::$T)
507508
xy = int128(x)*int128(y)
508509
(typemin($T) <= xy <= typemax($T)) || throw(OverflowError())
509-
return mod(xy,$T)
510+
return xy % $T
510511
end
511512
end
512513
else

‎base/pkg/types.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function intersect(A::VersionSet, B::VersionSet)
4444
VersionSet(ivals)
4545
end
4646
==(A::VersionSet, B::VersionSet) = A.intervals == B.intervals
47-
hash(s::VersionSet, h::Uint) = hash(s.intervals, h + mod(0x2fd2ca6efa023f44,Uint))
47+
hash(s::VersionSet, h::Uint) = hash(s.intervals, h + (0x2fd2ca6efa023f44 % Uint))
4848
deepcopy_internal(vs::VersionSet, ::ObjectIdDict) = VersionSet(copy(vs.intervals))
4949

5050
typealias Requires Dict{ByteString,VersionSet}

‎base/profile.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const UNKNOWN = LineInfo("?", "?", -1, true, 0)
104104
==(a::LineInfo, b::LineInfo) = a.line == b.line && a.fromC == b.fromC && a.func == b.func && a.file == b.file
105105

106106
function hash(li::LineInfo, h::Uint)
107-
h += mod(0xf4fbda67fe20ce88,Uint)
107+
h += 0xf4fbda67fe20ce88 % Uint
108108
h = hash(li.line, h)
109109
h = hash(li.file, h)
110110
h = hash(li.func, h)

‎base/random.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ rand(r::MersenneTwister) = dsfmt_genrand_close_open(r.state)
104104
dsfmt_randui32() = dsfmt_gv_genrand_uint32()
105105
dsfmt_randui64() = uint64(dsfmt_randui32()) | (uint64(dsfmt_randui32())<<32)
106106

107-
rand(::Type{Uint8}) = mod(rand(Uint32),Uint8)
108-
rand(::Type{Uint16}) = mod(rand(Uint32),Uint16)
107+
rand(::Type{Uint8}) = rand(Uint32) % Uint8
108+
rand(::Type{Uint16}) = rand(Uint32) % Uint16
109109
rand(::Type{Uint32}) = dsfmt_randui32()
110110
rand(::Type{Uint64}) = dsfmt_randui64()
111111
rand(::Type{Uint128}) = uint128(rand(Uint64))<<64 | rand(Uint64)
112112

113-
rand(::Type{Int8}) = mod(rand(Uint32),Int8)
114-
rand(::Type{Int16}) = mod(rand(Uint32),Int16)
113+
rand(::Type{Int8}) = rand(Uint32) % Int8
114+
rand(::Type{Int16}) = rand(Uint32) % Int16
115115
rand(::Type{Int32}) = reinterpret(Int32,rand(Uint32))
116116
rand(::Type{Int64}) = reinterpret(Int64,rand(Uint64))
117117
rand(::Type{Int128}) = reinterpret(Int128,rand(Uint128))
@@ -154,12 +154,12 @@ rem_knuth{T<:Unsigned}(a::T, b::T) = b != 0 ? a % b : a
154154

155155
# maximum multiple of k <= 2^bits(T) decremented by one,
156156
# that is 0xFFFFFFFF if k = typemax(T) - typemin(T) with intentional underflow
157-
maxmultiple(k::Uint32) = mod(div(0x0000000100000000,k + (k == 0))*k - 1, Uint32)
158-
maxmultiple(k::Uint64) = mod(div(0x00000000000000010000000000000000, k + (k == 0))*k - 1, Uint64)
157+
maxmultiple(k::Uint32) = (div(0x0000000100000000,k + (k == 0))*k - 1) % Uint32
158+
maxmultiple(k::Uint64) = (div(0x00000000000000010000000000000000, k + (k == 0))*k - 1) % Uint64
159159
# maximum multiple of k within 1:typemax(Uint128)
160160
maxmultiple(k::Uint128) = div(typemax(Uint128), k + (k == 0))*k - 1
161161
# maximum multiple of k within 1:2^32 or 1:2^64, depending on size
162-
maxmultiplemix(k::Uint64) = mod(div((k >> 32 != 0)*0x0000000000000000FFFFFFFF00000000 + 0x0000000100000000, k + (k == 0))*k - 1, Uint64)
162+
maxmultiplemix(k::Uint64) = (div((k >> 32 != 0)*0x0000000000000000FFFFFFFF00000000 + 0x0000000100000000, k + (k == 0))*k - 1) % Uint64
163163

164164
immutable RandIntGen{T<:Integer, U<:Unsigned}
165165
a::T # first element of the range
@@ -206,7 +206,7 @@ function rand{T<:Integer, U<:Unsigned}(g::RandIntGen{T,U})
206206
while x > g.u
207207
x = rand(U)
208208
end
209-
mod(unsigned(g.a) + rem_knuth(x, g.k), T)
209+
(unsigned(g.a) + rem_knuth(x, g.k)) % T
210210
end
211211

212212
rand{T<:Union(Signed,Unsigned,Bool,Char)}(r::UnitRange{T}) = rand(RandIntGen(r))

‎base/string.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ const memhash_seed = Uint === Uint64 ? 0x71e729fd56419c81 : 0x56419c81
661661

662662
function hash{T<:ByteString}(s::Union(T,SubString{T}), h::Uint)
663663
h += memhash_seed
664-
ccall(memhash, Uint, (Ptr{Uint8}, Csize_t, Uint32), s, sizeof(s), mod(h,Uint32)) + h
664+
ccall(memhash, Uint, (Ptr{Uint8}, Csize_t, Uint32), s, sizeof(s), h % Uint32) + h
665665
end
666666
hash(s::String, h::Uint) = hash(bytestring(s), h)
667667

‎base/version.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function isless(a::VersionNumber, b::VersionNumber)
151151
end
152152

153153
function hash(v::VersionNumber, h::Uint)
154-
h += mod(0x8ff4ffdb75f9fede,Uint)
154+
h += 0x8ff4ffdb75f9fede % Uint
155155
h = hash(v.major, h)
156156
h = hash(v.minor, h)
157157
h = hash(v.patch, h)

‎test/hashing.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function coerce(T::Type, x)
2323
if !(T<:Integer) || T===Bool
2424
convert(T, x)
2525
elseif sizeof(T) < sizeof(x)
26-
mod(x, T)
26+
x % T
2727
elseif sizeof(T) == sizeof(x)
2828
reinterpret(T, x)
2929
else

0 commit comments

Comments
 (0)
Please sign in to comment.