what's the reasonale of loghelper() in mathmodule.c

rockins ybc2084 at gmail.com
Wed Apr 9 10:38:43 CEST 2008

Hi all,

I downloaded Python-2.5.2.tar.bz2 and want to lean some math function
implementation in it. I found that mathmodule.c implements 'math'
module of python. In this file there's a function loghelper()(in
Python-2.5.2/Modules/mathmodule.c), it seems with this function's help
any base logarithm can be computed, its comments state as:

/* A decent logarithm is easy to compute even for huge longs, but libm
   do that by itself -- loghelper can.  func is log or log10, and name
   "log" or "log10".  Note that overflow isn't possible:  a long can
   no more than INT_MAX * SHIFT bits, so has value certainly less than
   2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is
   small enough to fit in an IEEE single.  log and log10 are even

static PyObject*
loghelper(PyObject* args, double (*func)(double), char *format,
PyObject *arg)

I cannot understand it well, can anyone explain me why and how
loghelper() can compute any base logarithm? Or could anyone give me
some reference(such as, books or papers)?

Thanks in advance,

-Rockins Chen

More information about the Python-list mailing list