Skip to content

Commit

Permalink
itrunc => mod: a few more integer modulus methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 15, 2014
1 parent d5555cf commit 2ee9c15
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,21 @@ for to in tuple(IntTypes...,Char), from in tuple(IntTypes...,Char,Bool)
@eval convert(::Type{$to}, x::($from)) = box($to,checked_trunc_uint($to,unbox($from,x)))
end
@eval mod(x::($from), ::Type{$to}) = box($to,trunc_int($to,unbox($from,x)))
elseif from.size < to.size || from===Bool
elseif from.size < to.size || from === Bool
if issubtype(from, Signed)
@eval convert(::Type{$to}, x::($from)) = box($to,sext_int($to,unbox($from,x)))
else
@eval convert(::Type{$to}, x::($from)) = box($to,zext_int($to,unbox($from,x)))
end
@eval mod(x::($from), ::Type{$to}) = convert($to,x)
else
if !(issubtype(from,Signed) === issubtype(to,Signed))
# raise InexactError if x's top bit is set
@eval convert(::Type{$to}, x::($from)) = box($to,check_top_bit(unbox($from,x)))
else
@eval convert(::Type{$to}, x::($from)) = box($to,unbox($from,x))
end
@eval itrunc(::Type{$to}, x::($from)) = box($to,unbox($from,x))
@eval mod(x::($from), ::Type{$to}) = box($to,unbox($from,x))
end
end
end
Expand Down

0 comments on commit 2ee9c15

Please sign in to comment.