summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 06:22:46 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 06:22:46 (GMT)
commitca2b69f765dd8a7f5c8e5c5346572519a8768ec4 (patch)
treee1a5f81f05f96d7f85313182316fdb070cfdf1bc /Modules/mathmodule.c
parent951cc0f474e4757e6954f0435952804211c5637c (diff)
downloadcpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.zip
cpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.tar.gz
cpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.tar.bz2
Move __builtins__.trunc() to math.trunc() per
http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue 1965.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 6469bde..cdc3057 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -155,6 +155,21 @@ FUNC1(tanh, tanh,
"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 @@ static PyMethodDef math_methods[] = {
{"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 */
};