diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-01-05 08:47:13 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-01-05 08:47:13 +0000 |
commit | a3508c1516cafdeb01fddb0585f8cc85196c1071 (patch) | |
tree | 2c969191b1ad6d1b8aafc05f3a401e2cda072179 /Objects/intobject.c | |
parent | cc20ec96be6bdb748fc1cbef9504e55f89d223cf (diff) | |
download | cpython-a3508c1516cafdeb01fddb0585f8cc85196c1071.tar.gz |
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 96d7f76ab1..edb8e4f55a 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -1056,43 +1056,11 @@ int_getN(PyIntObject *v, void *context) { return PyInt_FromLong((intptr_t)context); } -static PyObject * -int_round(PyObject *self, PyObject *args) -{ -#define UNDEF_NDIGITS (-0x7fffffff) /* Unlikely ndigits value */ - int ndigits = UNDEF_NDIGITS; - double x; - PyObject *res; - - if (!PyArg_ParseTuple(args, "|i", &ndigits)) - return NULL; - - if (ndigits == UNDEF_NDIGITS) - return int_float((PyIntObject *)self); - - /* If called with two args, defer to float.__round__(). */ - x = (double) PyInt_AS_LONG(self); - self = PyFloat_FromDouble(x); - if (self == NULL) - return NULL; - res = PyObject_CallMethod(self, "__round__", "i", ndigits); - Py_DECREF(self); - return res; -#undef UNDEF_NDIGITS -} - static PyMethodDef int_methods[] = { {"conjugate", (PyCFunction)int_int, METH_NOARGS, "Returns self, the complex conjugate of any int."}, {"__trunc__", (PyCFunction)int_int, METH_NOARGS, "Truncating an Integral returns itself."}, - {"__floor__", (PyCFunction)int_float, METH_NOARGS, - "Flooring an Integral returns itself."}, - {"__ceil__", (PyCFunction)int_float, METH_NOARGS, - "Ceiling of an Integral returns itself."}, - {"__round__", (PyCFunction)int_round, METH_VARARGS, - "Rounding an Integral returns itself.\n" - "Rounding with an ndigits arguments defers to float.__round__."}, {"__getnewargs__", (PyCFunction)int_getnewargs, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; |