mirror of https://github.com/python/cpython
Get rid of remnants of integer division
This commit is contained in:
parent
ed483ba63b
commit
bcc0db82dc
|
@ -158,7 +158,6 @@ typedef struct {
|
||||||
binaryfunc nb_add;
|
binaryfunc nb_add;
|
||||||
binaryfunc nb_subtract;
|
binaryfunc nb_subtract;
|
||||||
binaryfunc nb_multiply;
|
binaryfunc nb_multiply;
|
||||||
binaryfunc nb_divide;
|
|
||||||
binaryfunc nb_remainder;
|
binaryfunc nb_remainder;
|
||||||
binaryfunc nb_divmod;
|
binaryfunc nb_divmod;
|
||||||
ternaryfunc nb_power;
|
ternaryfunc nb_power;
|
||||||
|
@ -182,7 +181,6 @@ typedef struct {
|
||||||
binaryfunc nb_inplace_add;
|
binaryfunc nb_inplace_add;
|
||||||
binaryfunc nb_inplace_subtract;
|
binaryfunc nb_inplace_subtract;
|
||||||
binaryfunc nb_inplace_multiply;
|
binaryfunc nb_inplace_multiply;
|
||||||
binaryfunc nb_inplace_divide;
|
|
||||||
binaryfunc nb_inplace_remainder;
|
binaryfunc nb_inplace_remainder;
|
||||||
ternaryfunc nb_inplace_power;
|
ternaryfunc nb_inplace_power;
|
||||||
binaryfunc nb_inplace_lshift;
|
binaryfunc nb_inplace_lshift;
|
||||||
|
@ -192,7 +190,6 @@ typedef struct {
|
||||||
binaryfunc nb_inplace_or;
|
binaryfunc nb_inplace_or;
|
||||||
|
|
||||||
/* Added in release 2.2 */
|
/* Added in release 2.2 */
|
||||||
/* The following require the Py_TPFLAGS_HAVE_CLASS flag */
|
|
||||||
binaryfunc nb_floor_divide;
|
binaryfunc nb_floor_divide;
|
||||||
binaryfunc nb_true_divide;
|
binaryfunc nb_true_divide;
|
||||||
binaryfunc nb_inplace_floor_divide;
|
binaryfunc nb_inplace_floor_divide;
|
||||||
|
|
|
@ -1135,10 +1135,9 @@ class Decimal(object):
|
||||||
return ans
|
return ans
|
||||||
__rmul__ = __mul__
|
__rmul__ = __mul__
|
||||||
|
|
||||||
def __div__(self, other, context=None):
|
def __truediv__(self, other, context=None):
|
||||||
"""Return self / other."""
|
"""Return self / other."""
|
||||||
return self._divide(other, context=context)
|
return self._divide(other, context=context)
|
||||||
__truediv__ = __div__
|
|
||||||
|
|
||||||
def _divide(self, other, divmod = 0, context=None):
|
def _divide(self, other, divmod = 0, context=None):
|
||||||
"""Return a / b, to context.prec precision.
|
"""Return a / b, to context.prec precision.
|
||||||
|
@ -1306,13 +1305,12 @@ class Decimal(object):
|
||||||
ans = ans._fix(context)
|
ans = ans._fix(context)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def __rdiv__(self, other, context=None):
|
def __rtruediv__(self, other, context=None):
|
||||||
"""Swaps self/other and returns __div__."""
|
"""Swaps self/other and returns __truediv__."""
|
||||||
other = _convert_other(other)
|
other = _convert_other(other)
|
||||||
if other is NotImplemented:
|
if other is NotImplemented:
|
||||||
return other
|
return other
|
||||||
return other.__div__(self, context=context)
|
return other.__truediv__(self, context=context)
|
||||||
__rtruediv__ = __rdiv__
|
|
||||||
|
|
||||||
def __divmod__(self, other, context=None):
|
def __divmod__(self, other, context=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1384,9 +1382,9 @@ class Decimal(object):
|
||||||
rounding = context._set_rounding_decision(NEVER_ROUND)
|
rounding = context._set_rounding_decision(NEVER_ROUND)
|
||||||
|
|
||||||
if other._sign:
|
if other._sign:
|
||||||
comparison = other.__div__(Decimal(-2), context=context)
|
comparison = other.__truediv__(Decimal(-2), context=context)
|
||||||
else:
|
else:
|
||||||
comparison = other.__div__(Decimal(2), context=context)
|
comparison = other.__truediv__(Decimal(2), context=context)
|
||||||
|
|
||||||
context._set_rounding_decision(rounding)
|
context._set_rounding_decision(rounding)
|
||||||
context._regard_flags(*flags)
|
context._regard_flags(*flags)
|
||||||
|
@ -1751,7 +1749,7 @@ class Decimal(object):
|
||||||
if n < 0:
|
if n < 0:
|
||||||
#n is a long now, not Decimal instance
|
#n is a long now, not Decimal instance
|
||||||
n = -n
|
n = -n
|
||||||
mul = Decimal(1).__div__(mul, context=context)
|
mul = Decimal(1).__truediv__(mul, context=context)
|
||||||
|
|
||||||
spot = 1
|
spot = 1
|
||||||
while spot <= n:
|
while spot <= n:
|
||||||
|
@ -1972,7 +1970,7 @@ class Decimal(object):
|
||||||
rounding = context._set_rounding(ROUND_HALF_EVEN)
|
rounding = context._set_rounding(ROUND_HALF_EVEN)
|
||||||
while 1:
|
while 1:
|
||||||
context.prec = min(2*context.prec - 2, maxp)
|
context.prec = min(2*context.prec - 2, maxp)
|
||||||
ans = half.__mul__(ans.__add__(tmp.__div__(ans, context=context),
|
ans = half.__mul__(ans.__add__(tmp.__truediv__(ans, context=context),
|
||||||
context=context), context=context)
|
context=context), context=context)
|
||||||
if context.prec == maxp:
|
if context.prec == maxp:
|
||||||
break
|
break
|
||||||
|
@ -2454,7 +2452,7 @@ class Context(object):
|
||||||
>>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
|
>>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
|
||||||
Decimal("1.20E+6")
|
Decimal("1.20E+6")
|
||||||
"""
|
"""
|
||||||
return a.__div__(b, context=self)
|
return a.__truediv__(b, context=self)
|
||||||
|
|
||||||
def divide_int(self, a, b):
|
def divide_int(self, a, b):
|
||||||
"""Divides two numbers and returns the integer part of the result.
|
"""Divides two numbers and returns the integer part of the result.
|
||||||
|
|
|
@ -5,7 +5,7 @@ x += 1
|
||||||
x *= 2
|
x *= 2
|
||||||
x **= 2
|
x **= 2
|
||||||
x -= 8
|
x -= 8
|
||||||
x //= 2
|
x /= 2
|
||||||
x //= 1
|
x //= 1
|
||||||
x %= 12
|
x %= 12
|
||||||
x &= 2
|
x &= 2
|
||||||
|
@ -19,7 +19,7 @@ x[0] += 1
|
||||||
x[0] *= 2
|
x[0] *= 2
|
||||||
x[0] **= 2
|
x[0] **= 2
|
||||||
x[0] -= 8
|
x[0] -= 8
|
||||||
x[0] //= 2
|
x[0] /= 2
|
||||||
x[0] //= 2
|
x[0] //= 2
|
||||||
x[0] %= 12
|
x[0] %= 12
|
||||||
x[0] &= 2
|
x[0] &= 2
|
||||||
|
@ -33,7 +33,7 @@ x[0] += 1
|
||||||
x[0] *= 2
|
x[0] *= 2
|
||||||
x[0] **= 2
|
x[0] **= 2
|
||||||
x[0] -= 8
|
x[0] -= 8
|
||||||
x[0] //= 2
|
x[0] /= 2
|
||||||
x[0] //= 1
|
x[0] //= 1
|
||||||
x[0] %= 12
|
x[0] %= 12
|
||||||
x[0] &= 2
|
x[0] &= 2
|
||||||
|
@ -123,14 +123,6 @@ class testall:
|
||||||
print "__imul__ called"
|
print "__imul__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __div__(self, val):
|
|
||||||
print "__div__ called"
|
|
||||||
def __rdiv__(self, val):
|
|
||||||
print "__rdiv__ called"
|
|
||||||
def __idiv__(self, val):
|
|
||||||
print "__idiv__ called"
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __floordiv__(self, val):
|
def __floordiv__(self, val):
|
||||||
print "__floordiv__ called"
|
print "__floordiv__ called"
|
||||||
return self
|
return self
|
||||||
|
@ -147,6 +139,9 @@ class testall:
|
||||||
def __itruediv__(self, val):
|
def __itruediv__(self, val):
|
||||||
print "__itruediv__ called"
|
print "__itruediv__ called"
|
||||||
return self
|
return self
|
||||||
|
def __rtruediv__(self, val):
|
||||||
|
print "__rtruediv__ called"
|
||||||
|
return self
|
||||||
|
|
||||||
def __mod__(self, val):
|
def __mod__(self, val):
|
||||||
print "__mod__ called"
|
print "__mod__ called"
|
||||||
|
@ -217,16 +212,9 @@ x * 1
|
||||||
1 * x
|
1 * x
|
||||||
x *= 1
|
x *= 1
|
||||||
|
|
||||||
if 1/2 == 0:
|
x / 1
|
||||||
x / 1
|
1 / x
|
||||||
1 / x
|
x /= 1
|
||||||
x /= 1
|
|
||||||
else:
|
|
||||||
# True division is in effect, so "/" doesn't map to __div__ etc;
|
|
||||||
# but the canned expected-output file requires that those get called.
|
|
||||||
x.__div__(1)
|
|
||||||
x.__rdiv__(1)
|
|
||||||
x.__idiv__(1)
|
|
||||||
|
|
||||||
x // 1
|
x // 1
|
||||||
1 // x
|
1 // x
|
||||||
|
|
|
@ -140,8 +140,6 @@ class Rat(object):
|
||||||
return float(self) / other
|
return float(self) / other
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
__div__ = __truediv__
|
|
||||||
|
|
||||||
def __rtruediv__(self, other):
|
def __rtruediv__(self, other):
|
||||||
"""Divide two Rats, or a Rat and a number (reversed args)."""
|
"""Divide two Rats, or a Rat and a number (reversed args)."""
|
||||||
if isRat(other):
|
if isRat(other):
|
||||||
|
@ -152,8 +150,6 @@ class Rat(object):
|
||||||
return other / float(self)
|
return other / float(self)
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
__rdiv__ = __rtruediv__
|
|
||||||
|
|
||||||
def __floordiv__(self, other):
|
def __floordiv__(self, other):
|
||||||
"""Divide two Rats, returning the floored result."""
|
"""Divide two Rats, returning the floored result."""
|
||||||
if isint(other):
|
if isint(other):
|
||||||
|
|
|
@ -11,8 +11,8 @@ testmeths = [
|
||||||
"rsub",
|
"rsub",
|
||||||
"mul",
|
"mul",
|
||||||
"rmul",
|
"rmul",
|
||||||
"div",
|
"truediv",
|
||||||
"rdiv",
|
"rtruediv",
|
||||||
"mod",
|
"mod",
|
||||||
"rmod",
|
"rmod",
|
||||||
"divmod",
|
"divmod",
|
||||||
|
@ -134,16 +134,8 @@ testme - 1
|
||||||
testme * 1
|
testme * 1
|
||||||
1 * testme
|
1 * testme
|
||||||
|
|
||||||
if 1/2 == 0:
|
testme / 1
|
||||||
testme / 1
|
1 / testme
|
||||||
1 / testme
|
|
||||||
else:
|
|
||||||
# True division is in effect, so "/" doesn't map to __div__ etc; but
|
|
||||||
# the canned expected-output file requires that __div__ etc get called.
|
|
||||||
testme.__coerce__(1)
|
|
||||||
testme.__div__(1)
|
|
||||||
testme.__coerce__(1)
|
|
||||||
testme.__rdiv__(1)
|
|
||||||
|
|
||||||
testme % 1
|
testme % 1
|
||||||
1 % testme
|
1 % testme
|
||||||
|
|
|
@ -44,10 +44,10 @@ class MethodNumber:
|
||||||
def __rmul__(self,other):
|
def __rmul__(self,other):
|
||||||
return other * self.arg
|
return other * self.arg
|
||||||
|
|
||||||
def __div__(self,other):
|
def __truediv__(self,other):
|
||||||
return self.arg / other
|
return self.arg / other
|
||||||
|
|
||||||
def __rdiv__(self,other):
|
def __rtruediv__(self,other):
|
||||||
return other / self.arg
|
return other / self.arg
|
||||||
|
|
||||||
def __pow__(self,other):
|
def __pow__(self,other):
|
||||||
|
|
|
@ -55,19 +55,15 @@ class ComplexTest(unittest.TestCase):
|
||||||
if x != 0:
|
if x != 0:
|
||||||
q = z / x
|
q = z / x
|
||||||
self.assertClose(q, y)
|
self.assertClose(q, y)
|
||||||
q = z.__div__(x)
|
|
||||||
self.assertClose(q, y)
|
|
||||||
q = z.__truediv__(x)
|
q = z.__truediv__(x)
|
||||||
self.assertClose(q, y)
|
self.assertClose(q, y)
|
||||||
if y != 0:
|
if y != 0:
|
||||||
q = z / y
|
q = z / y
|
||||||
self.assertClose(q, x)
|
self.assertClose(q, x)
|
||||||
q = z.__div__(y)
|
|
||||||
self.assertClose(q, x)
|
|
||||||
q = z.__truediv__(y)
|
q = z.__truediv__(y)
|
||||||
self.assertClose(q, x)
|
self.assertClose(q, x)
|
||||||
|
|
||||||
def test_div(self):
|
def test_truediv(self):
|
||||||
simple_real = [float(i) for i in xrange(-5, 6)]
|
simple_real = [float(i) for i in xrange(-5, 6)]
|
||||||
simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
|
simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
|
||||||
for x in simple_complex:
|
for x in simple_complex:
|
||||||
|
@ -84,7 +80,7 @@ class ComplexTest(unittest.TestCase):
|
||||||
self.check_div(complex(random(), random()),
|
self.check_div(complex(random(), random()),
|
||||||
complex(random(), random()))
|
complex(random(), random()))
|
||||||
|
|
||||||
self.assertRaises(ZeroDivisionError, complex.__div__, 1+1j, 0+0j)
|
self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
|
||||||
# FIXME: The following currently crashes on Alpha
|
# FIXME: The following currently crashes on Alpha
|
||||||
# self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
|
# self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
|
||||||
|
|
||||||
|
|
|
@ -507,7 +507,7 @@ class DecimalImplicitConstructionTest(unittest.TestCase):
|
||||||
('+', '__add__', '__radd__'),
|
('+', '__add__', '__radd__'),
|
||||||
('-', '__sub__', '__rsub__'),
|
('-', '__sub__', '__rsub__'),
|
||||||
('*', '__mul__', '__rmul__'),
|
('*', '__mul__', '__rmul__'),
|
||||||
('/', '__div__', '__rdiv__'),
|
('/', '__truediv__', '__rtruediv__'),
|
||||||
('%', '__mod__', '__rmod__'),
|
('%', '__mod__', '__rmod__'),
|
||||||
('//', '__floordiv__', '__rfloordiv__'),
|
('//', '__floordiv__', '__rfloordiv__'),
|
||||||
('**', '__pow__', '__rpow__'),
|
('**', '__pow__', '__rpow__'),
|
||||||
|
@ -975,7 +975,6 @@ class DecimalUsabilityTest(unittest.TestCase):
|
||||||
|
|
||||||
checkSameDec("__abs__")
|
checkSameDec("__abs__")
|
||||||
checkSameDec("__add__", True)
|
checkSameDec("__add__", True)
|
||||||
checkSameDec("__div__", True)
|
|
||||||
checkSameDec("__divmod__", True)
|
checkSameDec("__divmod__", True)
|
||||||
checkSameDec("__cmp__", True)
|
checkSameDec("__cmp__", True)
|
||||||
checkSameDec("__float__")
|
checkSameDec("__float__")
|
||||||
|
@ -990,7 +989,6 @@ class DecimalUsabilityTest(unittest.TestCase):
|
||||||
checkSameDec("__pos__")
|
checkSameDec("__pos__")
|
||||||
checkSameDec("__pow__", True)
|
checkSameDec("__pow__", True)
|
||||||
checkSameDec("__radd__", True)
|
checkSameDec("__radd__", True)
|
||||||
checkSameDec("__rdiv__", True)
|
|
||||||
checkSameDec("__rdivmod__", True)
|
checkSameDec("__rdivmod__", True)
|
||||||
checkSameDec("__repr__")
|
checkSameDec("__repr__")
|
||||||
checkSameDec("__rfloordiv__", True)
|
checkSameDec("__rfloordiv__", True)
|
||||||
|
|
|
@ -29,10 +29,6 @@ def testbinop(a, b, res, expr="a+b", meth="__add__"):
|
||||||
if verbose: print "checking", expr
|
if verbose: print "checking", expr
|
||||||
dict = {'a': a, 'b': b}
|
dict = {'a': a, 'b': b}
|
||||||
|
|
||||||
# XXX Hack so this passes before 2.3 when -Qnew is specified.
|
|
||||||
if meth == "__div__" and 1/2 == 0.5:
|
|
||||||
meth = "__truediv__"
|
|
||||||
|
|
||||||
vereq(eval(expr, dict), res)
|
vereq(eval(expr, dict), res)
|
||||||
t = type(a)
|
t = type(a)
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
|
@ -4044,9 +4040,8 @@ def notimplemented():
|
||||||
('__add__', 'x + y', 'x += y'),
|
('__add__', 'x + y', 'x += y'),
|
||||||
('__sub__', 'x - y', 'x -= y'),
|
('__sub__', 'x - y', 'x -= y'),
|
||||||
('__mul__', 'x * y', 'x *= y'),
|
('__mul__', 'x * y', 'x *= y'),
|
||||||
('__truediv__', 'operator.truediv(x, y)', None),
|
('__truediv__', 'x / y', None),
|
||||||
('__floordiv__', 'operator.floordiv(x, y)', None),
|
('__floordiv__', 'x // y', None),
|
||||||
('__div__', 'x / y', 'x /= y'),
|
|
||||||
('__mod__', 'x % y', 'x %= y'),
|
('__mod__', 'x % y', 'x %= y'),
|
||||||
('__divmod__', 'divmod(x, y)', None),
|
('__divmod__', 'divmod(x, y)', None),
|
||||||
('__pow__', 'x ** y', 'x **= y'),
|
('__pow__', 'x ** y', 'x **= y'),
|
||||||
|
|
|
@ -144,11 +144,6 @@ class OperatorTestCase(unittest.TestCase):
|
||||||
self.failUnless(operator.delslice(a, 2, 8) is None)
|
self.failUnless(operator.delslice(a, 2, 8) is None)
|
||||||
self.assert_(a == [0, 1, 8, 9])
|
self.assert_(a == [0, 1, 8, 9])
|
||||||
|
|
||||||
def test_div(self):
|
|
||||||
self.failUnlessRaises(TypeError, operator.div, 5)
|
|
||||||
self.failUnlessRaises(TypeError, operator.div, None, None)
|
|
||||||
self.failUnless(operator.floordiv(5, 2) == 2)
|
|
||||||
|
|
||||||
def test_floordiv(self):
|
def test_floordiv(self):
|
||||||
self.failUnlessRaises(TypeError, operator.floordiv, 5)
|
self.failUnlessRaises(TypeError, operator.floordiv, 5)
|
||||||
self.failUnlessRaises(TypeError, operator.floordiv, None, None)
|
self.failUnlessRaises(TypeError, operator.floordiv, None, None)
|
||||||
|
@ -416,7 +411,6 @@ class OperatorTestCase(unittest.TestCase):
|
||||||
class C(object):
|
class C(object):
|
||||||
def __iadd__ (self, other): return "iadd"
|
def __iadd__ (self, other): return "iadd"
|
||||||
def __iand__ (self, other): return "iand"
|
def __iand__ (self, other): return "iand"
|
||||||
def __idiv__ (self, other): return "idiv"
|
|
||||||
def __ifloordiv__(self, other): return "ifloordiv"
|
def __ifloordiv__(self, other): return "ifloordiv"
|
||||||
def __ilshift__ (self, other): return "ilshift"
|
def __ilshift__ (self, other): return "ilshift"
|
||||||
def __imod__ (self, other): return "imod"
|
def __imod__ (self, other): return "imod"
|
||||||
|
@ -431,7 +425,6 @@ class OperatorTestCase(unittest.TestCase):
|
||||||
c = C()
|
c = C()
|
||||||
self.assertEqual(operator.iadd (c, 5), "iadd")
|
self.assertEqual(operator.iadd (c, 5), "iadd")
|
||||||
self.assertEqual(operator.iand (c, 5), "iand")
|
self.assertEqual(operator.iand (c, 5), "iand")
|
||||||
self.assertEqual(operator.idiv (c, 5), "idiv")
|
|
||||||
self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
|
self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
|
||||||
self.assertEqual(operator.ilshift (c, 5), "ilshift")
|
self.assertEqual(operator.ilshift (c, 5), "ilshift")
|
||||||
self.assertEqual(operator.imod (c, 5), "imod")
|
self.assertEqual(operator.imod (c, 5), "imod")
|
||||||
|
@ -446,7 +439,6 @@ class OperatorTestCase(unittest.TestCase):
|
||||||
self.assertEqual(operator.irepeat (c, 5), "imul")
|
self.assertEqual(operator.irepeat (c, 5), "imul")
|
||||||
self.assertEqual(operator.__iadd__ (c, 5), "iadd")
|
self.assertEqual(operator.__iadd__ (c, 5), "iadd")
|
||||||
self.assertEqual(operator.__iand__ (c, 5), "iand")
|
self.assertEqual(operator.__iand__ (c, 5), "iand")
|
||||||
self.assertEqual(operator.__idiv__ (c, 5), "idiv")
|
|
||||||
self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv")
|
self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv")
|
||||||
self.assertEqual(operator.__ilshift__ (c, 5), "ilshift")
|
self.assertEqual(operator.__ilshift__ (c, 5), "ilshift")
|
||||||
self.assertEqual(operator.__imod__ (c, 5), "imod")
|
self.assertEqual(operator.__imod__ (c, 5), "imod")
|
||||||
|
|
|
@ -40,6 +40,14 @@ Core and Builtins
|
||||||
- Exceptions *must* derive from BaseException.
|
- Exceptions *must* derive from BaseException.
|
||||||
|
|
||||||
- Integer division always returns a float. The -Q option is no more.
|
- Integer division always returns a float. The -Q option is no more.
|
||||||
|
All the following are gone:
|
||||||
|
* PyNumber_Divide and PyNumber_InPlaceDivide
|
||||||
|
* __div__, __rdiv__, and __idiv__
|
||||||
|
* nb_divide, nb_inplace_divide
|
||||||
|
* operator.div, operator.idiv, operator.__div__, operator.__idiv__
|
||||||
|
(Only __truediv__ and __floordiv__ remain, not sure how to handle them
|
||||||
|
if we want to re-use __div__ and friends. If we do, it will make
|
||||||
|
it harder to write code for both 2.x and 3.x.)
|
||||||
|
|
||||||
- 'as' and 'with' are keywords.
|
- 'as' and 'with' are keywords.
|
||||||
|
|
||||||
|
|
|
@ -3812,7 +3812,6 @@ static PyNumberMethods Simple_as_number = {
|
||||||
0, /* nb_add */
|
0, /* nb_add */
|
||||||
0, /* nb_subtract */
|
0, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
@ -4165,7 +4164,6 @@ static PyNumberMethods Pointer_as_number = {
|
||||||
0, /* nb_add */
|
0, /* nb_add */
|
||||||
0, /* nb_subtract */
|
0, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
|
|
@ -2080,7 +2080,6 @@ static PyNumberMethods delta_as_number = {
|
||||||
delta_add, /* nb_add */
|
delta_add, /* nb_add */
|
||||||
delta_subtract, /* nb_subtract */
|
delta_subtract, /* nb_subtract */
|
||||||
delta_multiply, /* nb_multiply */
|
delta_multiply, /* nb_multiply */
|
||||||
delta_divide, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
@ -2103,7 +2102,6 @@ static PyNumberMethods delta_as_number = {
|
||||||
0, /*nb_inplace_add*/
|
0, /*nb_inplace_add*/
|
||||||
0, /*nb_inplace_subtract*/
|
0, /*nb_inplace_subtract*/
|
||||||
0, /*nb_inplace_multiply*/
|
0, /*nb_inplace_multiply*/
|
||||||
0, /*nb_inplace_divide*/
|
|
||||||
0, /*nb_inplace_remainder*/
|
0, /*nb_inplace_remainder*/
|
||||||
0, /*nb_inplace_power*/
|
0, /*nb_inplace_power*/
|
||||||
0, /*nb_inplace_lshift*/
|
0, /*nb_inplace_lshift*/
|
||||||
|
@ -2665,7 +2663,6 @@ static PyNumberMethods date_as_number = {
|
||||||
date_add, /* nb_add */
|
date_add, /* nb_add */
|
||||||
date_subtract, /* nb_subtract */
|
date_subtract, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
@ -3441,7 +3438,6 @@ static PyNumberMethods time_as_number = {
|
||||||
0, /* nb_add */
|
0, /* nb_add */
|
||||||
0, /* nb_subtract */
|
0, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
@ -4526,7 +4522,6 @@ static PyNumberMethods datetime_as_number = {
|
||||||
datetime_add, /* nb_add */
|
datetime_add, /* nb_add */
|
||||||
datetime_subtract, /* nb_subtract */
|
datetime_subtract, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
|
|
@ -266,7 +266,7 @@ math_log(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ans = PyNumber_Divide(num, den);
|
ans = PyNumber_TrueDivide(num, den);
|
||||||
Py_DECREF(num);
|
Py_DECREF(num);
|
||||||
Py_DECREF(den);
|
Py_DECREF(den);
|
||||||
return ans;
|
return ans;
|
||||||
|
|
|
@ -65,7 +65,6 @@ spami(truth , PyObject_IsTrue)
|
||||||
spam2(op_add , PyNumber_Add)
|
spam2(op_add , PyNumber_Add)
|
||||||
spam2(op_sub , PyNumber_Subtract)
|
spam2(op_sub , PyNumber_Subtract)
|
||||||
spam2(op_mul , PyNumber_Multiply)
|
spam2(op_mul , PyNumber_Multiply)
|
||||||
spam2(op_div , PyNumber_Divide)
|
|
||||||
spam2(op_floordiv , PyNumber_FloorDivide)
|
spam2(op_floordiv , PyNumber_FloorDivide)
|
||||||
spam2(op_truediv , PyNumber_TrueDivide)
|
spam2(op_truediv , PyNumber_TrueDivide)
|
||||||
spam2(op_mod , PyNumber_Remainder)
|
spam2(op_mod , PyNumber_Remainder)
|
||||||
|
@ -83,7 +82,6 @@ spam2(op_or_ , PyNumber_Or)
|
||||||
spam2(op_iadd , PyNumber_InPlaceAdd)
|
spam2(op_iadd , PyNumber_InPlaceAdd)
|
||||||
spam2(op_isub , PyNumber_InPlaceSubtract)
|
spam2(op_isub , PyNumber_InPlaceSubtract)
|
||||||
spam2(op_imul , PyNumber_InPlaceMultiply)
|
spam2(op_imul , PyNumber_InPlaceMultiply)
|
||||||
spam2(op_idiv , PyNumber_InPlaceDivide)
|
|
||||||
spam2(op_ifloordiv , PyNumber_InPlaceFloorDivide)
|
spam2(op_ifloordiv , PyNumber_InPlaceFloorDivide)
|
||||||
spam2(op_itruediv , PyNumber_InPlaceTrueDivide)
|
spam2(op_itruediv , PyNumber_InPlaceTrueDivide)
|
||||||
spam2(op_imod , PyNumber_InPlaceRemainder)
|
spam2(op_imod , PyNumber_InPlaceRemainder)
|
||||||
|
@ -247,9 +245,8 @@ spam2(index, __index__, "index(a) -- Same as a.__index__()")
|
||||||
spam2(add,__add__, "add(a, b) -- Same as a + b.")
|
spam2(add,__add__, "add(a, b) -- Same as a + b.")
|
||||||
spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
|
spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
|
||||||
spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")
|
spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")
|
||||||
spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.")
|
|
||||||
spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.")
|
spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.")
|
||||||
spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b when __future__.division is in effect.")
|
spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b.")
|
||||||
spam2(mod,__mod__, "mod(a, b) -- Same as a % b.")
|
spam2(mod,__mod__, "mod(a, b) -- Same as a % b.")
|
||||||
spam2o(neg,__neg__, "neg(a) -- Same as -a.")
|
spam2o(neg,__neg__, "neg(a) -- Same as -a.")
|
||||||
spam2o(pos,__pos__, "pos(a) -- Same as +a.")
|
spam2o(pos,__pos__, "pos(a) -- Same as +a.")
|
||||||
|
@ -265,9 +262,8 @@ spam2(or_,__or__, "or_(a, b) -- Same as a | b.")
|
||||||
spam2(iadd,__iadd__, "iadd(a, b) -- Same as a += b.")
|
spam2(iadd,__iadd__, "iadd(a, b) -- Same as a += b.")
|
||||||
spam2(isub,__isub__, "isub(a, b) -- Same as a -= b.")
|
spam2(isub,__isub__, "isub(a, b) -- Same as a -= b.")
|
||||||
spam2(imul,__imul__, "imul(a, b) -- Same as a *= b.")
|
spam2(imul,__imul__, "imul(a, b) -- Same as a *= b.")
|
||||||
spam2(idiv,__idiv__, "idiv(a, b) -- Same as a /= b when __future__.division is not in effect.")
|
|
||||||
spam2(ifloordiv,__ifloordiv__, "ifloordiv(a, b) -- Same as a //= b.")
|
spam2(ifloordiv,__ifloordiv__, "ifloordiv(a, b) -- Same as a //= b.")
|
||||||
spam2(itruediv,__itruediv__, "itruediv(a, b) -- Same as a /= b when __future__.division is in effect.")
|
spam2(itruediv,__itruediv__, "itruediv(a, b) -- Same as a /= b.")
|
||||||
spam2(imod,__imod__, "imod(a, b) -- Same as a %= b.")
|
spam2(imod,__imod__, "imod(a, b) -- Same as a %= b.")
|
||||||
spam2(ilshift,__ilshift__, "ilshift(a, b) -- Same as a <<= b.")
|
spam2(ilshift,__ilshift__, "ilshift(a, b) -- Same as a <<= b.")
|
||||||
spam2(irshift,__irshift__, "irshift(a, b) -- Same as a >>= b.")
|
spam2(irshift,__irshift__, "irshift(a, b) -- Same as a >>= b.")
|
||||||
|
|
|
@ -625,7 +625,6 @@ BINARY_FUNC(PyNumber_And, nb_and, "&")
|
||||||
BINARY_FUNC(PyNumber_Lshift, nb_lshift, "<<")
|
BINARY_FUNC(PyNumber_Lshift, nb_lshift, "<<")
|
||||||
BINARY_FUNC(PyNumber_Rshift, nb_rshift, ">>")
|
BINARY_FUNC(PyNumber_Rshift, nb_rshift, ">>")
|
||||||
BINARY_FUNC(PyNumber_Subtract, nb_subtract, "-")
|
BINARY_FUNC(PyNumber_Subtract, nb_subtract, "-")
|
||||||
BINARY_FUNC(PyNumber_Divide, nb_divide, "/")
|
|
||||||
BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
|
BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
@ -765,7 +764,6 @@ INPLACE_BINOP(PyNumber_InPlaceAnd, nb_inplace_and, nb_and, "&=")
|
||||||
INPLACE_BINOP(PyNumber_InPlaceLshift, nb_inplace_lshift, nb_lshift, "<<=")
|
INPLACE_BINOP(PyNumber_InPlaceLshift, nb_inplace_lshift, nb_lshift, "<<=")
|
||||||
INPLACE_BINOP(PyNumber_InPlaceRshift, nb_inplace_rshift, nb_rshift, ">>=")
|
INPLACE_BINOP(PyNumber_InPlaceRshift, nb_inplace_rshift, nb_rshift, ">>=")
|
||||||
INPLACE_BINOP(PyNumber_InPlaceSubtract, nb_inplace_subtract, nb_subtract, "-=")
|
INPLACE_BINOP(PyNumber_InPlaceSubtract, nb_inplace_subtract, nb_subtract, "-=")
|
||||||
INPLACE_BINOP(PyNumber_InPlaceDivide, nb_inplace_divide, nb_divide, "/=")
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyNumber_InPlaceFloorDivide(PyObject *v, PyObject *w)
|
PyNumber_InPlaceFloorDivide(PyObject *v, PyObject *w)
|
||||||
|
|
|
@ -106,7 +106,6 @@ static PyNumberMethods bool_as_number = {
|
||||||
0, /* nb_add */
|
0, /* nb_add */
|
||||||
0, /* nb_subtract */
|
0, /* nb_subtract */
|
||||||
0, /* nb_multiply */
|
0, /* nb_multiply */
|
||||||
0, /* nb_divide */
|
|
||||||
0, /* nb_remainder */
|
0, /* nb_remainder */
|
||||||
0, /* nb_divmod */
|
0, /* nb_divmod */
|
||||||
0, /* nb_power */
|
0, /* nb_power */
|
||||||
|
@ -129,7 +128,6 @@ static PyNumberMethods bool_as_number = {
|
||||||
0, /* nb_inplace_add */
|
0, /* nb_inplace_add */
|
||||||
0, /* nb_inplace_subtract */
|
0, /* nb_inplace_subtract */
|
||||||
0, /* nb_inplace_multiply */
|
0, /* nb_inplace_multiply */
|
||||||
0, /* nb_inplace_divide */
|
|
||||||
0, /* nb_inplace_remainder */
|
0, /* nb_inplace_remainder */
|
||||||
0, /* nb_inplace_power */
|
0, /* nb_inplace_power */
|
||||||
0, /* nb_inplace_lshift */
|
0, /* nb_inplace_lshift */
|
||||||
|
|
|
@ -1551,7 +1551,6 @@ BINARY(instance_rshift, "rshift", PyNumber_Rshift)
|
||||||
BINARY(instance_add, "add", PyNumber_Add)
|
BINARY(instance_add, "add", PyNumber_Add)
|
||||||
BINARY(instance_sub, "sub", PyNumber_Subtract)
|
BINARY(instance_sub, "sub", PyNumber_Subtract)
|
||||||
BINARY(instance_mul, "mul", PyNumber_Multiply)
|
BINARY(instance_mul, "mul", PyNumber_Multiply)
|
||||||
BINARY(instance_div, "div", PyNumber_Divide)
|
|
||||||
BINARY(instance_mod, "mod", PyNumber_Remainder)
|
BINARY(instance_mod, "mod", PyNumber_Remainder)
|
||||||
BINARY(instance_divmod, "divmod", PyNumber_Divmod)
|
BINARY(instance_divmod, "divmod", PyNumber_Divmod)
|
||||||
BINARY(instance_floordiv, "floordiv", PyNumber_FloorDivide)
|
BINARY(instance_floordiv, "floordiv", PyNumber_FloorDivide)
|
||||||
|
@ -1565,7 +1564,6 @@ BINARY_INPLACE(instance_irshift, "rshift", PyNumber_InPlaceRshift)
|
||||||
BINARY_INPLACE(instance_iadd, "add", PyNumber_InPlaceAdd)
|
BINARY_INPLACE(instance_iadd, "add", PyNumber_InPlaceAdd)
|
||||||
BINARY_INPLACE(instance_isub, "sub", PyNumber_InPlaceSubtract)
|
BINARY_INPLACE(instance_isub, "sub", PyNumber_InPlaceSubtract)
|
||||||
BINARY_INPLACE(instance_imul, "mul", PyNumber_InPlaceMultiply)
|
BINARY_INPLACE(instance_imul, "mul", PyNumber_InPlaceMultiply)
|
||||||
BINARY_INPLACE(instance_idiv, "div", PyNumber_InPlaceDivide)
|
|
||||||
BINARY_INPLACE(instance_imod, "mod", PyNumber_InPlaceRemainder)
|
BINARY_INPLACE(instance_imod, "mod", PyNumber_InPlaceRemainder)
|
||||||
BINARY_INPLACE(instance_ifloordiv, "floordiv", PyNumber_InPlaceFloorDivide)
|
BINARY_INPLACE(instance_ifloordiv, "floordiv", PyNumber_InPlaceFloorDivide)
|
||||||
BINARY_INPLACE(instance_itruediv, "truediv", PyNumber_InPlaceTrueDivide)
|
BINARY_INPLACE(instance_itruediv, "truediv", PyNumber_InPlaceTrueDivide)
|
||||||
|
@ -2054,7 +2052,6 @@ static PyNumberMethods instance_as_number = {
|
||||||
(binaryfunc)instance_add, /* nb_add */
|
(binaryfunc)instance_add, /* nb_add */
|
||||||
(binaryfunc)instance_sub, /* nb_subtract */
|
(binaryfunc)instance_sub, /* nb_subtract */
|
||||||
(binaryfunc)instance_mul, /* nb_multiply */
|
(binaryfunc)instance_mul, /* nb_multiply */
|
||||||
(binaryfunc)instance_div, /* nb_divide */
|
|
||||||
(binaryfunc)instance_mod, /* nb_remainder */
|
(binaryfunc)instance_mod, /* nb_remainder */
|
||||||
(binaryfunc)instance_divmod, /* nb_divmod */
|
(binaryfunc)instance_divmod, /* nb_divmod */
|
||||||
(ternaryfunc)instance_pow, /* nb_power */
|
(ternaryfunc)instance_pow, /* nb_power */
|
||||||
|
@ -2077,7 +2074,6 @@ static PyNumberMethods instance_as_number = {
|
||||||
(binaryfunc)instance_iadd, /* nb_inplace_add */
|
(binaryfunc)instance_iadd, /* nb_inplace_add */
|
||||||
(binaryfunc)instance_isub, /* nb_inplace_subtract */
|
(binaryfunc)instance_isub, /* nb_inplace_subtract */
|
||||||
(binaryfunc)instance_imul, /* nb_inplace_multiply */
|
(binaryfunc)instance_imul, /* nb_inplace_multiply */
|
||||||
(binaryfunc)instance_idiv, /* nb_inplace_divide */
|
|
||||||
(binaryfunc)instance_imod, /* nb_inplace_remainder */
|
(binaryfunc)instance_imod, /* nb_inplace_remainder */
|
||||||
(ternaryfunc)instance_ipow, /* nb_inplace_power */
|
(ternaryfunc)instance_ipow, /* nb_inplace_power */
|
||||||
(binaryfunc)instance_ilshift, /* nb_inplace_lshift */
|
(binaryfunc)instance_ilshift, /* nb_inplace_lshift */
|
||||||
|
|
|
@ -381,27 +381,6 @@ complex_div(PyComplexObject *v, PyComplexObject *w)
|
||||||
return PyComplex_FromCComplex(quot);
|
return PyComplex_FromCComplex(quot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
complex_classic_div(PyComplexObject *v, PyComplexObject *w)
|
|
||||||
{
|
|
||||||
Py_complex quot;
|
|
||||||
|
|
||||||
if (Py_DivisionWarningFlag >= 2 &&
|
|
||||||
PyErr_Warn(PyExc_DeprecationWarning,
|
|
||||||
"classic complex division") < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
PyFPE_START_PROTECT("complex_classic_div", return 0)
|
|
||||||
errno = 0;
|
|
||||||
quot = c_quot(v->cval,w->cval);
|
|
||||||
PyFPE_END_PROTECT(quot)
|
|
||||||
if (errno == EDOM) {
|
|
||||||
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return PyComplex_FromCComplex(quot);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
complex_remainder(PyComplexObject *v, PyComplexObject *w)
|
complex_remainder(PyComplexObject *v, PyComplexObject *w)
|
||||||
{
|
{
|
||||||
|
@ -948,7 +927,6 @@ static PyNumberMethods complex_as_number = {
|
||||||
(binaryfunc)complex_add, /* nb_add */
|
(binaryfunc)complex_add, /* nb_add */
|
||||||
(binaryfunc)complex_sub, /* nb_subtract */
|
(binaryfunc)complex_sub, /* nb_subtract */
|
||||||
(binaryfunc)complex_mul, /* nb_multiply */
|
(binaryfunc)complex_mul, /* nb_multiply */
|
||||||
(binaryfunc)complex_classic_div, /* nb_divide */
|
|
||||||
(binaryfunc)complex_remainder, /* nb_remainder */
|
(binaryfunc)complex_remainder, /* nb_remainder */
|
||||||
(binaryfunc)complex_divmod, /* nb_divmod */
|
(binaryfunc)complex_divmod, /* nb_divmod */
|
||||||
(ternaryfunc)complex_pow, /* nb_power */
|
(ternaryfunc)complex_pow, /* nb_power */
|
||||||
|
@ -971,7 +949,6 @@ static PyNumberMethods complex_as_number = {
|
||||||
0, /* nb_inplace_add */
|
0, /* nb_inplace_add */
|
||||||
0, /* nb_inplace_subtract */
|
0, /* nb_inplace_subtract */
|
||||||
0, /* nb_inplace_multiply*/
|
0, /* nb_inplace_multiply*/
|
||||||
0, /* nb_inplace_divide */
|
|
||||||
0, /* nb_inplace_remainder */
|
0, /* nb_inplace_remainder */
|
||||||
0, /* nb_inplace_power */
|
0, /* nb_inplace_power */
|
||||||
0, /* nb_inplace_lshift */
|
0, /* nb_inplace_lshift */
|
||||||
|
|
|
@ -641,25 +641,6 @@ float_div(PyObject *v, PyObject *w)
|
||||||
return PyFloat_FromDouble(a);
|
return PyFloat_FromDouble(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
float_classic_div(PyObject *v, PyObject *w)
|
|
||||||
{
|
|
||||||
double a,b;
|
|
||||||
CONVERT_TO_DOUBLE(v, a);
|
|
||||||
CONVERT_TO_DOUBLE(w, b);
|
|
||||||
if (Py_DivisionWarningFlag >= 2 &&
|
|
||||||
PyErr_Warn(PyExc_DeprecationWarning, "classic float division") < 0)
|
|
||||||
return NULL;
|
|
||||||
if (b == 0.0) {
|
|
||||||
PyErr_SetString(PyExc_ZeroDivisionError, "float division");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyFPE_START_PROTECT("divide", return 0)
|
|
||||||
a = a / b;
|
|
||||||
PyFPE_END_PROTECT(a)
|
|
||||||
return PyFloat_FromDouble(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
float_rem(PyObject *v, PyObject *w)
|
float_rem(PyObject *v, PyObject *w)
|
||||||
{
|
{
|
||||||
|
@ -1128,7 +1109,6 @@ static PyNumberMethods float_as_number = {
|
||||||
(binaryfunc)float_add, /*nb_add*/
|
(binaryfunc)float_add, /*nb_add*/
|
||||||
(binaryfunc)float_sub, /*nb_subtract*/
|
(binaryfunc)float_sub, /*nb_subtract*/
|
||||||
(binaryfunc)float_mul, /*nb_multiply*/
|
(binaryfunc)float_mul, /*nb_multiply*/
|
||||||
(binaryfunc)float_classic_div, /*nb_divide*/
|
|
||||||
(binaryfunc)float_rem, /*nb_remainder*/
|
(binaryfunc)float_rem, /*nb_remainder*/
|
||||||
(binaryfunc)float_divmod, /*nb_divmod*/
|
(binaryfunc)float_divmod, /*nb_divmod*/
|
||||||
(ternaryfunc)float_pow, /*nb_power*/
|
(ternaryfunc)float_pow, /*nb_power*/
|
||||||
|
@ -1151,7 +1131,6 @@ static PyNumberMethods float_as_number = {
|
||||||
0, /* nb_inplace_add */
|
0, /* nb_inplace_add */
|
||||||
0, /* nb_inplace_subtract */
|
0, /* nb_inplace_subtract */
|
||||||
0, /* nb_inplace_multiply */
|
0, /* nb_inplace_multiply */
|
||||||
0, /* nb_inplace_divide */
|
|
||||||
0, /* nb_inplace_remainder */
|
0, /* nb_inplace_remainder */
|
||||||
0, /* nb_inplace_power */
|
0, /* nb_inplace_power */
|
||||||
0, /* nb_inplace_lshift */
|
0, /* nb_inplace_lshift */
|
||||||
|
|
|
@ -580,29 +580,8 @@ int_div(PyIntObject *x, PyIntObject *y)
|
||||||
case DIVMOD_OK:
|
case DIVMOD_OK:
|
||||||
return PyInt_FromLong(d);
|
return PyInt_FromLong(d);
|
||||||
case DIVMOD_OVERFLOW:
|
case DIVMOD_OVERFLOW:
|
||||||
return PyLong_Type.tp_as_number->nb_divide((PyObject *)x,
|
return PyLong_Type.tp_as_number->nb_floor_divide((PyObject *)x,
|
||||||
(PyObject *)y);
|
(PyObject *)y);
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
int_classic_div(PyIntObject *x, PyIntObject *y)
|
|
||||||
{
|
|
||||||
long xi, yi;
|
|
||||||
long d, m;
|
|
||||||
CONVERT_TO_LONG(x, xi);
|
|
||||||
CONVERT_TO_LONG(y, yi);
|
|
||||||
if (Py_DivisionWarningFlag &&
|
|
||||||
PyErr_Warn(PyExc_DeprecationWarning, "classic int division") < 0)
|
|
||||||
return NULL;
|
|
||||||
switch (i_divmod(xi, yi, &d, &m)) {
|
|
||||||
case DIVMOD_OK:
|
|
||||||
return PyInt_FromLong(d);
|
|
||||||
case DIVMOD_OVERFLOW:
|
|
||||||
return PyLong_Type.tp_as_number->nb_divide((PyObject *)x,
|
|
||||||
(PyObject *)y);
|
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1034,7 +1013,6 @@ static PyNumberMethods int_as_number = {
|
||||||
(binaryfunc)int_add, /*nb_add*/
|
(binaryfunc)int_add, /*nb_add*/
|
||||||
(binaryfunc)int_sub, /*nb_subtract*/
|
(binaryfunc)int_sub, /*nb_subtract*/
|
||||||
(binaryfunc)int_mul, /*nb_multiply*/
|
(binaryfunc)int_mul, /*nb_multiply*/
|
||||||
(binaryfunc)int_classic_div, /*nb_divide*/
|
|
||||||
(binaryfunc)int_mod, /*nb_remainder*/
|
(binaryfunc)int_mod, /*nb_remainder*/
|
||||||
(binaryfunc)int_divmod, /*nb_divmod*/
|
(binaryfunc)int_divmod, /*nb_divmod*/
|
||||||
(ternaryfunc)int_pow, /*nb_power*/
|
(ternaryfunc)int_pow, /*nb_power*/
|
||||||
|
@ -1057,7 +1035,6 @@ static PyNumberMethods int_as_number = {
|
||||||
0, /*nb_inplace_add*/
|
0, /*nb_inplace_add*/
|
||||||
0, /*nb_inplace_subtract*/
|
0, /*nb_inplace_subtract*/
|
||||||
0, /*nb_inplace_multiply*/
|
0, /*nb_inplace_multiply*/
|
||||||
0, /*nb_inplace_divide*/
|
|
||||||
0, /*nb_inplace_remainder*/
|
0, /*nb_inplace_remainder*/
|
||||||
0, /*nb_inplace_power*/
|
0, /*nb_inplace_power*/
|
||||||
0, /*nb_inplace_lshift*/
|
0, /*nb_inplace_lshift*/
|
||||||
|
|
|
@ -2354,22 +2354,6 @@ long_div(PyObject *v, PyObject *w)
|
||||||
return (PyObject *)div;
|
return (PyObject *)div;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
long_classic_div(PyObject *v, PyObject *w)
|
|
||||||
{
|
|
||||||
PyLongObject *a, *b, *div;
|
|
||||||
|
|
||||||
CONVERT_BINOP(v, w, &a, &b);
|
|
||||||
if (Py_DivisionWarningFlag &&
|
|
||||||
PyErr_Warn(PyExc_DeprecationWarning, "classic long division") < 0)
|
|
||||||
div = NULL;
|
|
||||||
else if (l_divmod(a, b, &div, NULL) < 0)
|
|
||||||
div = NULL;
|
|
||||||
Py_DECREF(a);
|
|
||||||
Py_DECREF(b);
|
|
||||||
return (PyObject *)div;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_true_divide(PyObject *v, PyObject *w)
|
long_true_divide(PyObject *v, PyObject *w)
|
||||||
{
|
{
|
||||||
|
@ -3130,7 +3114,6 @@ static PyNumberMethods long_as_number = {
|
||||||
(binaryfunc) long_add, /*nb_add*/
|
(binaryfunc) long_add, /*nb_add*/
|
||||||
(binaryfunc) long_sub, /*nb_subtract*/
|
(binaryfunc) long_sub, /*nb_subtract*/
|
||||||
(binaryfunc) long_mul, /*nb_multiply*/
|
(binaryfunc) long_mul, /*nb_multiply*/
|
||||||
(binaryfunc) long_classic_div, /*nb_divide*/
|
|
||||||
(binaryfunc) long_mod, /*nb_remainder*/
|
(binaryfunc) long_mod, /*nb_remainder*/
|
||||||
(binaryfunc) long_divmod, /*nb_divmod*/
|
(binaryfunc) long_divmod, /*nb_divmod*/
|
||||||
(ternaryfunc) long_pow, /*nb_power*/
|
(ternaryfunc) long_pow, /*nb_power*/
|
||||||
|
@ -3153,7 +3136,6 @@ static PyNumberMethods long_as_number = {
|
||||||
0, /* nb_inplace_add */
|
0, /* nb_inplace_add */
|
||||||
0, /* nb_inplace_subtract */
|
0, /* nb_inplace_subtract */
|
||||||
0, /* nb_inplace_multiply */
|
0, /* nb_inplace_multiply */
|
||||||
0, /* nb_inplace_divide */
|
|
||||||
0, /* nb_inplace_remainder */
|
0, /* nb_inplace_remainder */
|
||||||
0, /* nb_inplace_power */
|
0, /* nb_inplace_power */
|
||||||
0, /* nb_inplace_lshift */
|
0, /* nb_inplace_lshift */
|
||||||
|
|
|
@ -1755,7 +1755,6 @@ static PyNumberMethods set_as_number = {
|
||||||
0, /*nb_add*/
|
0, /*nb_add*/
|
||||||
(binaryfunc)set_sub, /*nb_subtract*/
|
(binaryfunc)set_sub, /*nb_subtract*/
|
||||||
0, /*nb_multiply*/
|
0, /*nb_multiply*/
|
||||||
0, /*nb_divide*/
|
|
||||||
0, /*nb_remainder*/
|
0, /*nb_remainder*/
|
||||||
0, /*nb_divmod*/
|
0, /*nb_divmod*/
|
||||||
0, /*nb_power*/
|
0, /*nb_power*/
|
||||||
|
@ -1778,7 +1777,6 @@ static PyNumberMethods set_as_number = {
|
||||||
0, /*nb_inplace_add*/
|
0, /*nb_inplace_add*/
|
||||||
(binaryfunc)set_isub, /*nb_inplace_subtract*/
|
(binaryfunc)set_isub, /*nb_inplace_subtract*/
|
||||||
0, /*nb_inplace_multiply*/
|
0, /*nb_inplace_multiply*/
|
||||||
0, /*nb_inplace_divide*/
|
|
||||||
0, /*nb_inplace_remainder*/
|
0, /*nb_inplace_remainder*/
|
||||||
0, /*nb_inplace_power*/
|
0, /*nb_inplace_power*/
|
||||||
0, /*nb_inplace_lshift*/
|
0, /*nb_inplace_lshift*/
|
||||||
|
@ -1867,7 +1865,6 @@ static PyNumberMethods frozenset_as_number = {
|
||||||
0, /*nb_add*/
|
0, /*nb_add*/
|
||||||
(binaryfunc)set_sub, /*nb_subtract*/
|
(binaryfunc)set_sub, /*nb_subtract*/
|
||||||
0, /*nb_multiply*/
|
0, /*nb_multiply*/
|
||||||
0, /*nb_divide*/
|
|
||||||
0, /*nb_remainder*/
|
0, /*nb_remainder*/
|
||||||
0, /*nb_divmod*/
|
0, /*nb_divmod*/
|
||||||
0, /*nb_power*/
|
0, /*nb_power*/
|
||||||
|
|
|
@ -3408,7 +3408,6 @@ static PyNumberMethods string_as_number = {
|
||||||
0, /*nb_add*/
|
0, /*nb_add*/
|
||||||
0, /*nb_subtract*/
|
0, /*nb_subtract*/
|
||||||
0, /*nb_multiply*/
|
0, /*nb_multiply*/
|
||||||
0, /*nb_divide*/
|
|
||||||
string_mod, /*nb_remainder*/
|
string_mod, /*nb_remainder*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3014,7 +3014,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
|
||||||
COPYNUM(nb_add);
|
COPYNUM(nb_add);
|
||||||
COPYNUM(nb_subtract);
|
COPYNUM(nb_subtract);
|
||||||
COPYNUM(nb_multiply);
|
COPYNUM(nb_multiply);
|
||||||
COPYNUM(nb_divide);
|
|
||||||
COPYNUM(nb_remainder);
|
COPYNUM(nb_remainder);
|
||||||
COPYNUM(nb_divmod);
|
COPYNUM(nb_divmod);
|
||||||
COPYNUM(nb_power);
|
COPYNUM(nb_power);
|
||||||
|
@ -3037,7 +3036,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
|
||||||
COPYNUM(nb_inplace_add);
|
COPYNUM(nb_inplace_add);
|
||||||
COPYNUM(nb_inplace_subtract);
|
COPYNUM(nb_inplace_subtract);
|
||||||
COPYNUM(nb_inplace_multiply);
|
COPYNUM(nb_inplace_multiply);
|
||||||
COPYNUM(nb_inplace_divide);
|
|
||||||
COPYNUM(nb_inplace_remainder);
|
COPYNUM(nb_inplace_remainder);
|
||||||
COPYNUM(nb_inplace_power);
|
COPYNUM(nb_inplace_power);
|
||||||
COPYNUM(nb_inplace_lshift);
|
COPYNUM(nb_inplace_lshift);
|
||||||
|
@ -3045,12 +3043,11 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
|
||||||
COPYNUM(nb_inplace_and);
|
COPYNUM(nb_inplace_and);
|
||||||
COPYNUM(nb_inplace_xor);
|
COPYNUM(nb_inplace_xor);
|
||||||
COPYNUM(nb_inplace_or);
|
COPYNUM(nb_inplace_or);
|
||||||
if (base->tp_flags & Py_TPFLAGS_CHECKTYPES) {
|
COPYNUM(nb_true_divide);
|
||||||
COPYNUM(nb_true_divide);
|
COPYNUM(nb_floor_divide);
|
||||||
COPYNUM(nb_floor_divide);
|
COPYNUM(nb_inplace_true_divide);
|
||||||
COPYNUM(nb_inplace_true_divide);
|
COPYNUM(nb_inplace_floor_divide);
|
||||||
COPYNUM(nb_inplace_floor_divide);
|
/* XXX(nnorwitz): we don't need to check flags do we? */
|
||||||
}
|
|
||||||
if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
|
if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
|
||||||
COPYNUM(nb_index);
|
COPYNUM(nb_index);
|
||||||
}
|
}
|
||||||
|
@ -4291,7 +4288,6 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
|
||||||
SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__")
|
SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__")
|
||||||
SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__")
|
SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__")
|
||||||
SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__")
|
SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__")
|
||||||
SLOT1BIN(slot_nb_divide, nb_divide, "__div__", "__rdiv__")
|
|
||||||
SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__")
|
SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__")
|
||||||
SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__")
|
SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__")
|
||||||
|
|
||||||
|
@ -4470,7 +4466,6 @@ SLOT0(slot_nb_hex, "__hex__")
|
||||||
SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
|
||||||
SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
|
||||||
SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
|
||||||
SLOT1(slot_nb_inplace_divide, "__idiv__", PyObject *, "O")
|
|
||||||
SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
|
||||||
SLOT1(slot_nb_inplace_power, "__ipow__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_power, "__ipow__", PyObject *, "O")
|
||||||
SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O")
|
SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O")
|
||||||
|
@ -5077,10 +5072,6 @@ static slotdef slotdefs[] = {
|
||||||
"*"),
|
"*"),
|
||||||
RBINSLOT("__rmul__", nb_multiply, slot_nb_multiply,
|
RBINSLOT("__rmul__", nb_multiply, slot_nb_multiply,
|
||||||
"*"),
|
"*"),
|
||||||
BINSLOT("__div__", nb_divide, slot_nb_divide,
|
|
||||||
"/"),
|
|
||||||
RBINSLOT("__rdiv__", nb_divide, slot_nb_divide,
|
|
||||||
"/"),
|
|
||||||
BINSLOT("__mod__", nb_remainder, slot_nb_remainder,
|
BINSLOT("__mod__", nb_remainder, slot_nb_remainder,
|
||||||
"%"),
|
"%"),
|
||||||
RBINSLOT("__rmod__", nb_remainder, slot_nb_remainder,
|
RBINSLOT("__rmod__", nb_remainder, slot_nb_remainder,
|
||||||
|
@ -5130,8 +5121,6 @@ static slotdef slotdefs[] = {
|
||||||
wrap_binaryfunc, "-"),
|
wrap_binaryfunc, "-"),
|
||||||
IBSLOT("__imul__", nb_inplace_multiply, slot_nb_inplace_multiply,
|
IBSLOT("__imul__", nb_inplace_multiply, slot_nb_inplace_multiply,
|
||||||
wrap_binaryfunc, "*"),
|
wrap_binaryfunc, "*"),
|
||||||
IBSLOT("__idiv__", nb_inplace_divide, slot_nb_inplace_divide,
|
|
||||||
wrap_binaryfunc, "/"),
|
|
||||||
IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
|
IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
|
||||||
wrap_binaryfunc, "%"),
|
wrap_binaryfunc, "%"),
|
||||||
IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
|
IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
|
||||||
|
|
|
@ -6445,7 +6445,6 @@ static PyNumberMethods unicode_as_number = {
|
||||||
0, /*nb_add*/
|
0, /*nb_add*/
|
||||||
0, /*nb_subtract*/
|
0, /*nb_subtract*/
|
||||||
0, /*nb_multiply*/
|
0, /*nb_multiply*/
|
||||||
0, /*nb_divide*/
|
|
||||||
unicode_mod, /*nb_remainder*/
|
unicode_mod, /*nb_remainder*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -471,7 +471,6 @@ proxy_compare(PyObject *proxy, PyObject *v)
|
||||||
WRAP_BINARY(proxy_add, PyNumber_Add)
|
WRAP_BINARY(proxy_add, PyNumber_Add)
|
||||||
WRAP_BINARY(proxy_sub, PyNumber_Subtract)
|
WRAP_BINARY(proxy_sub, PyNumber_Subtract)
|
||||||
WRAP_BINARY(proxy_mul, PyNumber_Multiply)
|
WRAP_BINARY(proxy_mul, PyNumber_Multiply)
|
||||||
WRAP_BINARY(proxy_div, PyNumber_Divide)
|
|
||||||
WRAP_BINARY(proxy_mod, PyNumber_Remainder)
|
WRAP_BINARY(proxy_mod, PyNumber_Remainder)
|
||||||
WRAP_BINARY(proxy_divmod, PyNumber_Divmod)
|
WRAP_BINARY(proxy_divmod, PyNumber_Divmod)
|
||||||
WRAP_TERNARY(proxy_pow, PyNumber_Power)
|
WRAP_TERNARY(proxy_pow, PyNumber_Power)
|
||||||
|
@ -490,7 +489,6 @@ WRAP_UNARY(proxy_float, PyNumber_Float)
|
||||||
WRAP_BINARY(proxy_iadd, PyNumber_InPlaceAdd)
|
WRAP_BINARY(proxy_iadd, PyNumber_InPlaceAdd)
|
||||||
WRAP_BINARY(proxy_isub, PyNumber_InPlaceSubtract)
|
WRAP_BINARY(proxy_isub, PyNumber_InPlaceSubtract)
|
||||||
WRAP_BINARY(proxy_imul, PyNumber_InPlaceMultiply)
|
WRAP_BINARY(proxy_imul, PyNumber_InPlaceMultiply)
|
||||||
WRAP_BINARY(proxy_idiv, PyNumber_InPlaceDivide)
|
|
||||||
WRAP_BINARY(proxy_imod, PyNumber_InPlaceRemainder)
|
WRAP_BINARY(proxy_imod, PyNumber_InPlaceRemainder)
|
||||||
WRAP_TERNARY(proxy_ipow, PyNumber_InPlacePower)
|
WRAP_TERNARY(proxy_ipow, PyNumber_InPlacePower)
|
||||||
WRAP_BINARY(proxy_ilshift, PyNumber_InPlaceLshift)
|
WRAP_BINARY(proxy_ilshift, PyNumber_InPlaceLshift)
|
||||||
|
@ -591,7 +589,6 @@ static PyNumberMethods proxy_as_number = {
|
||||||
(binaryfunc)proxy_add, /*nb_add*/
|
(binaryfunc)proxy_add, /*nb_add*/
|
||||||
(binaryfunc)proxy_sub, /*nb_subtract*/
|
(binaryfunc)proxy_sub, /*nb_subtract*/
|
||||||
(binaryfunc)proxy_mul, /*nb_multiply*/
|
(binaryfunc)proxy_mul, /*nb_multiply*/
|
||||||
(binaryfunc)proxy_div, /*nb_divide*/
|
|
||||||
(binaryfunc)proxy_mod, /*nb_remainder*/
|
(binaryfunc)proxy_mod, /*nb_remainder*/
|
||||||
(binaryfunc)proxy_divmod, /*nb_divmod*/
|
(binaryfunc)proxy_divmod, /*nb_divmod*/
|
||||||
(ternaryfunc)proxy_pow, /*nb_power*/
|
(ternaryfunc)proxy_pow, /*nb_power*/
|
||||||
|
@ -614,7 +611,6 @@ static PyNumberMethods proxy_as_number = {
|
||||||
(binaryfunc)proxy_iadd, /*nb_inplace_add*/
|
(binaryfunc)proxy_iadd, /*nb_inplace_add*/
|
||||||
(binaryfunc)proxy_isub, /*nb_inplace_subtract*/
|
(binaryfunc)proxy_isub, /*nb_inplace_subtract*/
|
||||||
(binaryfunc)proxy_imul, /*nb_inplace_multiply*/
|
(binaryfunc)proxy_imul, /*nb_inplace_multiply*/
|
||||||
(binaryfunc)proxy_idiv, /*nb_inplace_divide*/
|
|
||||||
(binaryfunc)proxy_imod, /*nb_inplace_remainder*/
|
(binaryfunc)proxy_imod, /*nb_inplace_remainder*/
|
||||||
(ternaryfunc)proxy_ipow, /*nb_inplace_power*/
|
(ternaryfunc)proxy_ipow, /*nb_inplace_power*/
|
||||||
(binaryfunc)proxy_ilshift, /*nb_inplace_lshift*/
|
(binaryfunc)proxy_ilshift, /*nb_inplace_lshift*/
|
||||||
|
|
|
@ -431,7 +431,6 @@ static PyNumberMethods PyHKEY_NumberMethods =
|
||||||
PyHKEY_binaryFailureFunc, /* nb_add */
|
PyHKEY_binaryFailureFunc, /* nb_add */
|
||||||
PyHKEY_binaryFailureFunc, /* nb_subtract */
|
PyHKEY_binaryFailureFunc, /* nb_subtract */
|
||||||
PyHKEY_binaryFailureFunc, /* nb_multiply */
|
PyHKEY_binaryFailureFunc, /* nb_multiply */
|
||||||
PyHKEY_binaryFailureFunc, /* nb_divide */
|
|
||||||
PyHKEY_binaryFailureFunc, /* nb_remainder */
|
PyHKEY_binaryFailureFunc, /* nb_remainder */
|
||||||
PyHKEY_binaryFailureFunc, /* nb_divmod */
|
PyHKEY_binaryFailureFunc, /* nb_divmod */
|
||||||
PyHKEY_ternaryFailureFunc, /* nb_power */
|
PyHKEY_ternaryFailureFunc, /* nb_power */
|
||||||
|
|
Loading…
Reference in New Issue