gamma approximation : what is module cmath and where is it located ?

pdlemper at pdlemper at
Thu Jul 30 00:24:11 EDT 2009

The following numerical approximation for Euler's Gamma function
is found in

from cmath import *
# Coefficients used by the GNU Scientific Library
g = 7
p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,
     771.32342877765313, -176.61502916214059, 12.507343278686905,
     -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]
def gamma(z):
    z = complex(z)
    # Reflection formula
    if z.real < 0.5:
        return pi / (sin(pi*z)*gamma(1-z))
        z -= 1
        x = p[0]
        for i in range(1, g+2):
            x += p[i]/(z+i)
        t = z + g + 0.5
        return sqrt(2*pi) * t**(z+0.5) * exp(-t) * x

This works in Python 3.0    
But I can't figure out where it gets "cmath".    Searching the Python 
directory reveals no more than a test_cmath.  The only cmath I can find
is a header file in another directory  turboc++\Borland\include\

dir(cmath) reveals 23 functions overlapping the 37 functions of
the math module.

What is cmath, where did it come from and how does it differ from
the standard math module  ?

                                   I saw the number 4 in silver,  Guido
                                     (apologies to Wm Carlos Williams)

More information about the Python-list mailing list