[Python-checkins] python/dist/src/Modules mathmodule.c,2.69,2.70

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
2002年12月14日 11:51:36 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21375/Modules
Modified Files:
	mathmodule.c 
Log Message:
Apply SF patch 652930: Add optional base argument to math.log(x[, base]).
Index: mathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.69
retrieving revision 2.70
diff -C2 -d -r2.69 -r2.70
*** mathmodule.c	2 Aug 2002 02:27:13 -0000	2.69
--- mathmodule.c	14 Dec 2002 19:51:33 -0000	2.70
***************
*** 222,237 ****
 
 static PyObject*
! loghelper(PyObject* args, double (*func)(double), char *name)
 {
- 	PyObject *arg;
- 	char format[16];
- 
- 	/* See whether this is a long. */
- 	format[0] = 'O';
- 	format[1] = ':';
- 	strcpy(format + 2, name);
- 	if (! PyArg_ParseTuple(args, format, &arg))
- 		return NULL;
- 
 	/* If it is long, do it ourselves. */
 	if (PyLong_Check(arg)) {
--- 222,227 ----
 
 static PyObject*
! loghelper(PyObject* args, double (*func)(double), char *format, PyObject *arg)
 {
 	/* If it is long, do it ourselves. */
 	if (PyLong_Check(arg)) {
***************
*** 253,257 ****
 
 	/* Else let libm handle it by itself. */
- 	format[0] = 'd';
 	return math_1(args, func, format);
 }
--- 243,246 ----
***************
*** 260,273 ****
 math_log(PyObject *self, PyObject *args)
 {
! 	return loghelper(args, log, "log");
 }
 
 PyDoc_STRVAR(math_log_doc,
! "log(x) -> the natural logarithm (base e) of x.");
 
 static PyObject *
 math_log10(PyObject *self, PyObject *args)
 {
! 	return loghelper(args, log10, "log10");
 }
 
--- 249,305 ----
 math_log(PyObject *self, PyObject *args)
 {
! 	PyObject *arg;
! 	PyObject *base = NULL;
! 	PyObject *num, *den;
! 	PyObject *ans;
! 	PyObject *newargs;
! 
! 	if (! PyArg_ParseTuple(args, "O|O:log", &arg, &base))
! 		return NULL;
! 	if (base == NULL)
! 		return loghelper(args, log, "d:log", arg);
! 
! 	newargs = PyTuple_New(1);
! 	if (newargs == NULL)
! 		return NULL;
! 	Py_INCREF(arg);
! 	PyTuple_SET_ITEM(newargs, 0, arg);
! 	num = loghelper(newargs, log, "d:log", arg);
! 	Py_DECREF(newargs);
! 	if (num == NULL)
! 		return NULL;
! 
! 	newargs = PyTuple_New(1);
! 	if (newargs == NULL) {
! 		Py_DECREF(num);
! 		return NULL;
! 	}
! 	Py_INCREF(base);
! 	PyTuple_SET_ITEM(newargs, 0, base);
! 	den = loghelper(newargs, log, "d:log", base);
! 	Py_DECREF(newargs);
! 	if (den == NULL) {
! 		Py_DECREF(num);
! 		return NULL;
! 	}
! 
! 	ans = PyNumber_Divide(num, den);
! 	Py_DECREF(num);
! 	Py_DECREF(den);
! 	return ans;
 }
 
 PyDoc_STRVAR(math_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.");
 
 static PyObject *
 math_log10(PyObject *self, PyObject *args)
 {
! 	PyObject *arg;
! 
! 	if (! PyArg_ParseTuple(args, "O:log10", &arg))
! 		return NULL;
! 	return loghelper(args, log10, "d:log10", arg);
 }
 

AltStyle によって変換されたページ (->オリジナル) /