diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-01-05 08:47:13 (GMT) |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-01-05 08:47:13 (GMT) |
commit | 9871d8fe22566acf68bf336d04d3a1dbd51f3269 (patch) | |
tree | 89540b4ff5f893e36c916534be2f07b5a7166fc1 /Modules | |
parent | f7476c4d463b5770b98d980bcd9bff3db981445d (diff) | |
download | cpython-9871d8fe22566acf68bf336d04d3a1dbd51f3269.zip cpython-9871d8fe22566acf68bf336d04d3a1dbd51f3269.tar.gz cpython-9871d8fe22566acf68bf336d04d3a1dbd51f3269.tar.bz2 |
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 'Modules')
-rw-r--r-- | Modules/mathmodule.c | 50 |
1 files changed, 6 insertions, 44 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 44a9d93..5e52e78 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -107,28 +107,9 @@ FUNC1(atan, atan, FUNC2(atan2, atan2, "atan2(y, x)\n\nReturn the arc tangent (measured in radians) of y/x.\n" "Unlike atan(y/x), the signs of both x and y are considered.") - -static PyObject * math_ceil(PyObject *self, PyObject *number) { - static PyObject *ceil_str = NULL; - PyObject *method; - - if (ceil_str == NULL) { - ceil_str = PyString_FromString("__ceil__"); - if (ceil_str == NULL) - return NULL; - } - - method = _PyType_Lookup(Py_Type(number), ceil_str); - if (method == NULL) - return math_1(number, ceil); - else - return PyObject_CallFunction(method, "O", number); -} - -PyDoc_STRVAR(math_ceil_doc, - "ceil(x)\n\nReturn the ceiling of x as a float.\n" - "This is the smallest integral value >= x."); - +FUNC1(ceil, ceil, + "ceil(x)\n\nReturn the ceiling of x as a float.\n" + "This is the smallest integral value >= x.") FUNC1(cos, cos, "cos(x)\n\nReturn the cosine of x (measured in radians).") FUNC1(cosh, cosh, @@ -147,28 +128,9 @@ FUNC1(exp, exp, "exp(x)\n\nReturn e raised to the power of x.") FUNC1(fabs, fabs, "fabs(x)\n\nReturn the absolute value of the float x.") - -static PyObject * math_floor(PyObject *self, PyObject *number) { - static PyObject *floor_str = NULL; - PyObject *method; - - if (floor_str == NULL) { - floor_str = PyString_FromString("__floor__"); - if (floor_str == NULL) - return NULL; - } - - method = _PyType_Lookup(Py_Type(number), floor_str); - if (method == NULL) - return math_1(number, floor); - else - return PyObject_CallFunction(method, "O", number); -} - -PyDoc_STRVAR(math_floor_doc, - "floor(x)\n\nReturn the floor of x as a float.\n" - "This is the largest integral value <= x."); - +FUNC1(floor, floor, + "floor(x)\n\nReturn the floor of x as a float.\n" + "This is the largest integral value <= x.") FUNC2(fmod, fmod, "fmod(x,y)\n\nReturn fmod(x, y), according to platform C." " x % y may differ.") |