[Python-checkins] python/dist/src/Modules mathmodule.c,2.66,2.67

rhettinger@sourceforge.net rhettinger@sourceforge.net
Sun, 12 May 2002 20:56:13 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv5484

Modified Files:
	mathmodule.c 
Log Message:
Added degrees() and radians() to mathmodule.  Closes patch 552452 and
feature request 426539.


Index: mathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.66
retrieving revision 2.67
diff -C2 -d -r2.66 -r2.67
*** mathmodule.c	6 Sep 2001 08:16:17 -0000	2.66
--- mathmodule.c	13 May 2002 03:56:10 -0000	2.67
***************
*** 275,278 ****
--- 275,303 ----
  "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[] = {
***************
*** 284,287 ****
--- 309,313 ----
  	{"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},
***************
*** 295,298 ****
--- 321,325 ----
  	{"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},