Mercurial > cpython-lru_cache-weakref
diff Modules/mathmodule.c @ 23427:a4d675b8b53c legacy-trunk
Added degrees() and radians() to mathmodule. Closes patch 552452 and
feature request 426539.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Mon, 13 May 2002 03:56:10 +0000 |
| parents | 64bcef1702ad |
| children | ed1ba37a46b7 |
line wrap: on
line diff
--- a/Modules/mathmodule.c Mon May 13 03:55:01 2002 +0000 +++ b/Modules/mathmodule.c Mon May 13 03:56:10 2002 +0000 @@ -274,6 +274,31 @@ static char math_log10_doc[] = "log10(x) -> the base 10 logarithm of x."; +static const double degToRad = 3.141592653589793238462643383 / 180.0; + +static PyObject * +math_degrees(PyObject *self, PyObject *args) +{ + double x; + if (! PyArg_ParseTuple(args, "d:degrees", &x)) + return NULL; + return PyFloat_FromDouble(x / degToRad); +} + +static char math_degrees_doc[] = +"degrees(x) -> converts angle x from radians to degrees"; + +static PyObject * +math_radians(PyObject *self, PyObject *args) +{ + double x; + if (! PyArg_ParseTuple(args, "d:radians", &x)) + return NULL; + return PyFloat_FromDouble(x * degToRad); +} + +static char math_radians_doc[] = +"radians(x) -> converts angle x from degrees to radians"; static PyMethodDef math_methods[] = { {"acos", math_acos, METH_VARARGS, math_acos_doc}, @@ -283,6 +308,7 @@ {"ceil", math_ceil, METH_VARARGS, math_ceil_doc}, {"cos", math_cos, METH_VARARGS, math_cos_doc}, {"cosh", math_cosh, METH_VARARGS, math_cosh_doc}, + {"degrees", math_degrees, METH_VARARGS, math_degrees_doc}, {"exp", math_exp, METH_VARARGS, math_exp_doc}, {"fabs", math_fabs, METH_VARARGS, math_fabs_doc}, {"floor", math_floor, METH_VARARGS, math_floor_doc}, @@ -294,6 +320,7 @@ {"log10", math_log10, METH_VARARGS, math_log10_doc}, {"modf", math_modf, METH_VARARGS, math_modf_doc}, {"pow", math_pow, METH_VARARGS, math_pow_doc}, + {"radians", math_radians, METH_VARARGS, math_radians_doc}, {"sin", math_sin, METH_VARARGS, math_sin_doc}, {"sinh", math_sinh, METH_VARARGS, math_sinh_doc}, {"sqrt", math_sqrt, METH_VARARGS, math_sqrt_doc},
