static PyObject *
math_log(PyObject *self, PyObject *args)
{
	PyObject *arg;
	PyObject *base = NULL;
	PyObject *num, *den;
	PyObject *ans;

	if (!PyArg_UnpackTuple(args, "log", 1, 2, &arg, &base))
		return NULL;

	num = loghelper(arg, log, "log");
	if (num == NULL || base == NULL)
		return num;

	den = loghelper(base, log, "log");
	if (den == NULL) {
		Py_DECREF(num);
		return NULL;
	}

	ans = PyNumber_TrueDivide(num, den);
	Py_DECREF(num);
	Py_DECREF(den);
	return ans;
}
Example #2
0
static PyObject *
math_log10(PyObject *self, PyObject *args)
{
	PyObject *arg;

	if (!PyArg_UnpackTuple(args, "log10", 1, 1, &arg))
		return NULL;
	return loghelper(args, log10, "d:log10", arg);
}
Example #3
0
static PyObject *
math_log(PyObject *self, PyObject *args)
{
	PyObject *arg;
	PyObject *base = NULL;
	PyObject *num, *den;
	PyObject *ans;
	PyObject *newargs;

	if (!PyArg_UnpackTuple(args, "log", 1, 2, &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;
}
static PyObject *
math_log10(PyObject *self, PyObject *arg)
{
	return loghelper(arg, log10, "log10");
}