Skip to content

Commit

Permalink
MAINT: Change wrap_int definition to use mask
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed Jun 6, 2019
1 parent 2834002 commit f9f277d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions numpy/random/common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,8 @@ cdef double kahan_sum(double *darr, np.npy_intp n):

cdef object wrap_int(object val, object bits):
"""Wraparound to place an integer into the interval [0, 2**bits)"""
upper = int(2)**int(bits)
if not 0<= val < upper:
divisor = val // upper
val = val - upper * divisor
return val
mask = ~(~int(0) << bits)
return val & mask


cdef np.ndarray int_to_array(object value, object name, object bits, object uint_size):
Expand Down

0 comments on commit f9f277d

Please sign in to comment.