[Python-checkins] python/dist/src/Modules cmathmodule.c,2.32,2.33

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Mon Jun 14 03:40:11 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29762/Modules

Modified Files:
	cmathmodule.c 
Log Message:
Patch #826074: cmath.log optional base argument, fixes #823209
(Contributed by Andrew Gaul.)



Index: cmathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cmathmodule.c,v
retrieving revision 2.32
retrieving revision 2.33
diff -C2 -d -r2.32 -r2.33
*** cmathmodule.c	2 Aug 2002 02:27:13 -0000	2.32
--- cmathmodule.c	14 Jun 2004 07:40:09 -0000	2.33
***************
*** 21,24 ****
--- 21,25 ----
  static Py_complex c_prodi(Py_complex);
  static Py_complex c_sqrt(Py_complex);
+ static PyObject * math_error(void);
  
  
***************
*** 165,173 ****
  }
  
- PyDoc_STRVAR(c_log_doc,
- "log(x)\n"
- "\n"
- "Return the natural logarithm of x.");
- 
  
  static Py_complex
--- 166,169 ----
***************
*** 313,316 ****
--- 309,337 ----
  "Return the hyperbolic tangent of x.");
  
+ static PyObject *
+ cmath_log(PyObject *self, PyObject *args)
+ {
+ 	Py_complex x;
+ 	Py_complex y;
+ 
+ 	if (!PyArg_ParseTuple(args, "D|D", &x, &y))
+ 		return NULL;
+ 
+ 	errno = 0;
+ 	PyFPE_START_PROTECT("complex function", return 0)
+ 	x = c_log(x);
+ 	if (PyTuple_GET_SIZE(args) == 2)
+ 		x = c_quot(x, c_log(y));
+ 	PyFPE_END_PROTECT(x)
+ 	if (errno != 0)
+ 		return math_error();
+ 	Py_ADJUST_ERANGE2(x.real, x.imag);
+ 	return PyComplex_FromCComplex(x);
+ }
+ 
+ PyDoc_STRVAR(cmath_log_doc,
+ "log(x[, base]) -> the logarithm of x to the given base.\n\
+ If the base not specified, returns the natural logarithm (base e) of x.");
+ 
  
  /* And now the glue to make them available from Python: */
***************
*** 359,363 ****
  FUNC1(cmath_cosh, c_cosh)
  FUNC1(cmath_exp, c_exp)
- FUNC1(cmath_log, c_log)
  FUNC1(cmath_log10, c_log10)
  FUNC1(cmath_sin, c_sin)
--- 380,383 ----
***************
*** 382,386 ****
  	{"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
  	{"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
! 	{"log",    cmath_log,   METH_VARARGS, c_log_doc},
  	{"log10",  cmath_log10, METH_VARARGS, c_log10_doc},
  	{"sin",    cmath_sin,   METH_VARARGS, c_sin_doc},
--- 402,406 ----
  	{"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
  	{"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
! 	{"log",    cmath_log,   METH_VARARGS, cmath_log_doc},
  	{"log10",  cmath_log10, METH_VARARGS, c_log10_doc},
  	{"sin",    cmath_sin,   METH_VARARGS, c_sin_doc},




More information about the Python-checkins mailing list