Mercurial > cpython-lru_cache-weakref
diff Modules/mathmodule.c @ 45079:492b302aded6 legacy-trunk
Move __builtins__.trunc() to math.trunc() per
http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue
1965.
| author | Jeffrey Yasskin <jyasskin@gmail.com> |
|---|---|
| date | Fri, 01 Feb 2008 06:22:46 +0000 |
| parents | 8e435bdd4bc8 |
| children | ce9816f53690 |
line wrap: on
line diff
--- a/Modules/mathmodule.c Thu Jan 31 23:08:23 2008 +0000 +++ b/Modules/mathmodule.c Fri Feb 01 06:22:46 2008 +0000 @@ -155,6 +155,21 @@ "tanh(x)\n\nReturn the hyperbolic tangent of x.") static PyObject * +math_trunc(PyObject *self, PyObject *number) +{ + /* XXX: The py3k branch gets better errors for this by using + _PyType_Lookup(), but since float's mro isn't set in py2.6, + we just use PyObject_CallMethod here. */ + return PyObject_CallMethod(number, "__trunc__", NULL); +} + +PyDoc_STRVAR(math_trunc_doc, +"trunc(x:Real) -> Integral\n" +"\n" +"Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic" +"method."); + +static PyObject * math_frexp(PyObject *self, PyObject *arg) { int i; @@ -377,6 +392,7 @@ {"sqrt", math_sqrt, METH_O, math_sqrt_doc}, {"tan", math_tan, METH_O, math_tan_doc}, {"tanh", math_tanh, METH_O, math_tanh_doc}, + {"trunc", math_trunc, METH_O, math_trunc_doc}, {NULL, NULL} /* sentinel */ };
