Beispiel #1
0
def int_c_mod(x, y):
    """Return the result of the C-style 'x % y'.  This differs from the
    Python-style division if (x < 0  xor y < 0).
    """
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #2
0
def int_c_mod(x, y):
    """Return the result of the C-style 'x % y'.  This differs from the
    Python-style division if (x < 0  xor y < 0).
    """
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #3
0
def int_mod_zer(x, y):
    '''#define OP_INT_MOD_ZER(x,y,r,err) \
        if ((y)) { OP_INT_MOD(x,y,r,err); } \
        else FAIL_ZER(err, "integer modulo")
    '''
    if y:
        return llop.int_mod(Signed, x, y)
    else:
        raise ZeroDivisionError("integer modulo")
Beispiel #4
0
def llong_mod_zer(x, y):
    '''#define OP_LLONG_MOD_ZER(x,y,r) \
      if ((y)) { OP_LLONG_MOD(x,y,r); } \
      else FAIL_ZER("integer modulo")
    '''
    if y:
        return llop.int_mod(SignedLongLong, x, y)
    else:
        raise ZeroDivisionError("integer modulo")
Beispiel #5
0
def llong_mod_zer(x, y):
    '''#define OP_LLONG_MOD_ZER(x,y,r) \
      if ((y)) { OP_LLONG_MOD(x,y,r); } \
      else FAIL_ZER("integer modulo")
    '''
    if y:
        return llop.int_mod(SignedLongLong, x, y)
    else:
        raise ZeroDivisionError("integer modulo")
Beispiel #6
0
def int_mod_zer(x, y):
    '''#define OP_INT_MOD_ZER(x,y,r,err) \
        if ((y)) { OP_INT_MOD(x,y,r,err); } \
        else FAIL_ZER(err, "integer modulo")
    '''
    if y:
        return llop.int_mod(Signed, x, y)
    else:
        raise ZeroDivisionError("integer modulo")
Beispiel #7
0
def int_mod_ovf(x, y):
    '''#define OP_INT_MOD_OVF(x,y,r,err) \
        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
                FAIL_OVF(err, "integer modulo"); \
        OP_INT_MOD(x,y,r,err)
    '''
    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
        raise OverflowError("integer modulo")
    else:
        return llop.int_mod(Signed, x, y)
Beispiel #8
0
def test_int_floordiv_mod():
    from rpython.rtyper.lltypesystem.lloperation import llop
    from rpython.jit.codewriter.support import _ll_2_int_floordiv, _ll_2_int_mod
    for x in range(-6, 7):
        for y in range(-3, 4):
            if y != 0:
                assert (_ll_2_int_floordiv(x, y) ==
                        llop.int_floordiv(lltype.Signed, x, y))
                assert (_ll_2_int_mod(x, y) ==
                        llop.int_mod(lltype.Signed, x, y))
def test_int_floordiv_mod():
    from rpython.rtyper.lltypesystem.lloperation import llop
    from rpython.jit.codewriter.support import _ll_2_int_floordiv, _ll_2_int_mod
    for x in range(-6, 7):
        for y in range(-3, 4):
            if y != 0:
                assert (_ll_2_int_floordiv(x, y) == llop.int_floordiv(
                    lltype.Signed, x, y))
                assert (_ll_2_int_mod(x,
                                      y) == llop.int_mod(lltype.Signed, x, y))
Beispiel #10
0
def int_mod_ovf(x, y):
    '''#define OP_INT_MOD_OVF(x,y,r,err) \
        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
                FAIL_OVF(err, "integer modulo"); \
        OP_INT_MOD(x,y,r,err)
    '''
    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
        raise OverflowError("integer modulo")
    else:
        return llop.int_mod(Signed, x, y)
Beispiel #11
0
 def prim_remainder(self, right, universe):
     if isinstance(right, BigInteger):
         d, r = _divrem(rbigint.fromint(self._embedded_integer),
                        right.get_embedded_biginteger())
         return universe.new_biginteger(r)
     elif isinstance(right, Double):
         return self._to_double(universe).prim_remainder(right, universe)
     else:
         l = self._embedded_integer
         r = right.get_embedded_integer()
         return universe.new_integer(llop.int_mod(lltype.Signed, l, r))
Beispiel #12
0
 def prim_remainder(self, right, universe):
     if isinstance(right, BigInteger):
         d, r = _divrem(rbigint.fromint(self._embedded_integer),
                        right.get_embedded_biginteger())
         return universe.new_biginteger(r)
     elif isinstance(right, Double):
         return self._to_double(universe).prim_remainder(right, universe)
     else:
         l = self._embedded_integer
         r = right.get_embedded_integer()
         return universe.new_integer(llop.int_mod(lltype.Signed, l, r))
Beispiel #13
0
def _ll_2_int_mod_ovf(x, y):
    if x == -sys.maxint - 1 and y == -1:
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #14
0
def ll_int_py_mod_nonnegargs(x, y):
    from rpython.rlib.debug import ll_assert
    r = llop.int_mod(Signed, x, y)                 # <= truncates like in C
    ll_assert(r >= 0, "int_py_mod_nonnegargs(): one arg is negative")
    return r
Beispiel #15
0
def int_mod(space, n, m):
    return space.wrap(llop.int_mod(lltype.Signed, n, m))
Beispiel #16
0
def ll_int_py_mod(x, y):
    r = llop.int_mod(Signed, x, y)  # <= truncates like in C
    if y < 0: u = -r
    else: u = r
    return r + (y & (u >> INT_BITS_1))
Beispiel #17
0
def ll_int_py_mod(x, y):
    r = llop.int_mod(Signed, x, y)                 # <= truncates like in C
    if y < 0: u = -r
    else:     u = r
    return r + (y & (u >> INT_BITS_1))
Beispiel #18
0
def _ll_2_int_mod_ovf(x, y):
    #see comment in _ll_2_int_floordiv_ovf
    if (x == -sys.maxint - 1) & (y == -1):
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #19
0
def _ll_2_int_mod_zer(x, y):
    if y == 0:
        raise ZeroDivisionError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #20
0
def _ll_2_int_mod_ovf_zer(x, y):
    if y == 0:
        raise ZeroDivisionError
    if x == -sys.maxint - 1 and y == -1:
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #21
0
def ll_int_py_mod_nonnegargs(x, y):
    from rpython.rlib.debug import ll_assert
    r = llop.int_mod(Signed, x, y)  # <= truncates like in C
    ll_assert(r >= 0, "int_py_mod_nonnegargs(): one arg is negative")
    return r
Beispiel #22
0
def _ll_2_int_mod_ovf(x, y):
    if x == -sys.maxint - 1 and y == -1:
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #23
0
def _ll_2_int_mod_zer(x, y):
    if y == 0:
        raise ZeroDivisionError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #24
0
def int_mod(space, n, m):
    return space.wrap(llop.int_mod(lltype.Signed, n, m))
Beispiel #25
0
def _ll_2_int_mod_ovf_zer(x, y):
    if y == 0:
        raise ZeroDivisionError
    if x == -sys.maxint - 1 and y == -1:
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)
Beispiel #26
0
def _ll_2_int_mod_ovf(x, y):
    #see comment in _ll_2_int_floordiv_ovf
    if (x == -sys.maxint - 1) & (y == -1):
        raise OverflowError
    return llop.int_mod(lltype.Signed, x, y)