Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: math-improvements Changeset: r95453:0f144096d308 Date: 2018-12-11 12:13 +0100 http://bitbucket.org/pypy/pypy/changeset/0f144096d308/
Log: typos, fix whitespace and a test diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py --- a/pypy/objspace/std/longobject.py +++ b/pypy/objspace/std/longobject.py @@ -442,6 +442,8 @@ return descr_binop, descr_rbinop descr_add, descr_radd = _make_generic_descr_binop('add') + + # XXX should support fast int version of rsub descr_sub, descr_rsub = _make_generic_descr_binop_noncommutative('sub') descr_mul, descr_rmul = _make_generic_descr_binop('mul') descr_and, descr_rand = _make_generic_descr_binop('and') @@ -481,10 +483,10 @@ raise oefmt(space.w_OverflowError, "shift count too large") return W_LongObject(self.num.lshift(shift)) - def _int_lshift(self, space, w_other): - if w_other < 0: + def _int_lshift(self, space, other): + if other < 0: raise oefmt(space.w_ValueError, "negative shift count") - return W_LongObject(self.num.lshift(w_other)) + return W_LongObject(self.num.lshift(other)) descr_lshift, descr_rlshift = _make_descr_binop(_lshift, _int_lshift) @@ -497,11 +499,11 @@ raise oefmt(space.w_OverflowError, "shift count too large") return newlong(space, self.num.rshift(shift)) - def _int_rshift(self, space, w_other): - if w_other < 0: + def _int_rshift(self, space, other): + if other < 0: raise oefmt(space.w_ValueError, "negative shift count") - return newlong(space, self.num.rshift(w_other)) + return newlong(space, self.num.rshift(other)) descr_rshift, descr_rrshift = _make_descr_binop(_rshift, _int_rshift) def _floordiv(self, space, w_other): @@ -512,9 +514,9 @@ "long division or modulo by zero") return newlong(space, z) - def _int_floordiv(self, space, w_other): + def _int_floordiv(self, space, other): try: - z = self.num.int_floordiv(w_other) + z = self.num.int_floordiv(other) except ZeroDivisionError: raise oefmt(space.w_ZeroDivisionError, "long division or modulo by zero") @@ -533,9 +535,9 @@ "long division or modulo by zero") return newlong(space, z) - def _int_mod(self, space, w_other): + def _int_mod(self, space, other): try: - z = self.num.int_mod(w_other) + z = self.num.int_mod(other) except ZeroDivisionError: raise oefmt(space.w_ZeroDivisionError, "long division or modulo by zero") @@ -549,15 +551,15 @@ raise oefmt(space.w_ZeroDivisionError, "long division or modulo by zero") return space.newtuple([newlong(space, div), newlong(space, mod)]) - - def _int_divmod(self, space, w_other): + + def _int_divmod(self, space, other): try: - div, mod = self.num.int_divmod(w_other) + div, mod = self.num.int_divmod(other) except ZeroDivisionError: raise oefmt(space.w_ZeroDivisionError, "long division or modulo by zero") return space.newtuple([newlong(space, div), newlong(space, mod)]) - + descr_divmod, descr_rdivmod = _make_descr_binop(_divmod, _int_divmod) diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py +++ b/pypy/objspace/std/test/test_longobject.py @@ -234,7 +234,7 @@ q, r = divmod(100L, 11) assert q == 9L assert r == 1L - + def test_format(self): assert repr(12345678901234567890) == '12345678901234567890L' assert str(12345678901234567890) == '12345678901234567890' diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -598,7 +598,7 @@ if not int_in_valid_range(other): # Fallback to Long. - return self.lt(rbigint.fromint(other)) + return self.le(rbigint.fromint(other)) return _x_int_lt(self, other, True) @@ -1199,7 +1199,7 @@ z._normalize() return z - lshift._always_inline_ = True # It's so fast that it's always benefitial. + lshift._always_inline_ = True # It's so fast that it's always beneficial. @jit.elidable def lqshift(self, int_other): @@ -1219,7 +1219,7 @@ z.setdigit(oldsize, accum) z._normalize() return z - lqshift._always_inline_ = True # It's so fast that it's always benefitial. + lqshift._always_inline_ = True # It's so fast that it's always beneficial. @jit.elidable def rshift(self, int_other, dont_invert=False): @@ -1262,7 +1262,7 @@ z.setdigit(0, z.digit(0)+1) z._normalize() return z - rshift._always_inline_ = 'try' # It's so fast that it's always benefitial. + rshift._always_inline_ = 'try' # It's so fast that it's always beneficial. @jit.elidable def rqshift(self, int_other): @@ -1287,7 +1287,7 @@ wordshift += 1 z._normalize() return z - rshift._always_inline_ = 'try' # It's so fast that it's always benefitial. + rshift._always_inline_ = 'try' # It's so fast that it's always beneficial. @jit.elidable def abs_rshift_and_mask(self, bigshiftcount, mask): diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -647,24 +647,22 @@ num = (x << y) + x f1 = rbigint.fromlong(num) nf1 = rbigint.fromlong(-num) - + for z in range(1, 31): - res1 = f1.lqshift(z).tolong() - res2 = f1.rqshift(z).tolong() - res3 = nf1.lqshift(z).tolong() - - + res1 = f1.lqshift(z).tolong() + res2 = f1.rqshift(z).tolong() + res3 = nf1.lqshift(z).tolong() + assert res1 == num << z assert res2 == num >> z assert res3 == -num << z - - + # Large digit for x in range((1 << SHIFT) - 10, (1 << SHIFT) + 10): f1 = rbigint.fromlong(x) - assert f1.rqshift(SHIFT).tolong() == x >> SHIFT + assert f1.rqshift(SHIFT).tolong() == x >> SHIFT assert f1.rqshift(SHIFT+1).tolong() == x >> (SHIFT+1) - + def test_from_list_n_bits(self): for x in ([3L ** 30L, 5L ** 20L, 7 ** 300] + [1L << i for i in range(130)] + diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py --- a/rpython/rtyper/lltypesystem/lloperation.py +++ b/rpython/rtyper/lltypesystem/lloperation.py @@ -343,7 +343,7 @@ 'ulllong_lshift': LLOp(canfold=True), # args (r_ulonglonglong, int) 'ulllong_rshift': LLOp(canfold=True), # args (r_ulonglonglong, int) 'ulllong_xor': LLOp(canfold=True), - + 'cast_primitive': LLOp(canfold=True), 'cast_bool_to_int': LLOp(canfold=True), 'cast_bool_to_uint': LLOp(canfold=True), diff --git a/rpython/rtyper/lltypesystem/opimpl.py b/rpython/rtyper/lltypesystem/opimpl.py --- a/rpython/rtyper/lltypesystem/opimpl.py +++ b/rpython/rtyper/lltypesystem/opimpl.py @@ -376,7 +376,7 @@ assert isinstance(x, r_ulonglonglong) assert is_valid_int(y) return r_ulonglonglong(x >> y) - + def op_same_as(x): return x diff --git a/rpython/rtyper/rint.py b/rpython/rtyper/rint.py --- a/rpython/rtyper/rint.py +++ b/rpython/rtyper/rint.py @@ -482,7 +482,7 @@ if y == 0: raise ZeroDivisionError("unsigned longlonglong division") return ll_ulllong_py_div(x, y) - + # ---------- mod ---------- @jit.oopspec("int.py_mod(x, y)") @@ -562,7 +562,7 @@ if y == 0: raise ZeroDivisionError return ll_lllong_py_mod(x, y) - + @jit.dont_look_inside def ll_ulllong_py_mod(x, y): return llop.ulllong_mod(UnsignedLongLongLong, x, y) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit