[Tutor] math, cmath and all that ...

Guillermo Fernandez guillermo.fernandez@epfl.ch
Fri, 09 Aug 2002 10:07:04 +0930


Hi!

> Where is the module math? Or what is its special character?
> It's not in Lib (as for instance string), but its also not built-in.
> Like cmath, os, sys, ... ? [Perhaps it is, that they are written in C,
> do they constitute dlls or what?]

I'm using python2.2 and I'll try to show the logic I followed to answer
this question.

I've made a little search (find is your friend, and if you don't have
it, think about installing a real shell into your Windows box, like
http://www.cygwin.com/).

guille@guille:~ >  find /usr/lib/python2.2/ -name "*math*" -print 2>
/dev/null 
/usr/lib/python2.2/test/test_cmath.py
/usr/lib/python2.2/test/test_math.py
/usr/lib/python2.2/test/test_cmath.pyc
/usr/lib/python2.2/test/test_cmath.pyo
/usr/lib/python2.2/test/test_math.pyc
/usr/lib/python2.2/test/test_math.pyo
/usr/lib/python2.2/test/output/test_math
/usr/lib/python2.2/lib-dynload/cmath.so
/usr/lib/python2.2/lib-dynload/math.so

The .pyc (python compiled) and .pyo (python compiled with optimisation)
does not really help us, so we forget them.

I've had a look at the sources of test/test_math.py and this seems to be
a program that allow to test all the functions of the math module (with
a name like that, it's quite logic :-)

The next logical step is to look at the .so files. The .so files
indicate a shared library, so probably they where writen in C and
compiled in the installation of python.

A little Google search shows this page:
http://cvs.astro-wise.org:4711/math.html
that sais about the lib-dynload/math.so that "This module is always
available.  It provides access to the mathematical functions defined by
the C standard."

This seems to said that, as I thought, it's a C file.

I decide then to have a look at the sources of Python:
guille@guille:~/Python-2.2.1 > find . -name "*math*" -print
./Doc/lib/libmath.tex
./Doc/lib/libcmath.tex
./Lib/test/test_cmath.py
./Lib/test/test_math.py
./Lib/test/output/test_math
./Modules/mathmodule.c
./Modules/cmathmodule.c

Seems that the file we are looking for is Modules/mathmodule.c

I had a look to the source and it seems to be the math module you are
looking for :-)

But maybe I did not understand your question... in that case, sorry for
the long mail.

Good luck!

Guille