Sophie

Sophie

distrib > Mandriva > 2009.1 > x86_64 > by-pkgid > 72e0913cefe7683427338e51dd70bbde > files > 221

python-cython-0.11.3-1mdv2009.1.x86_64.rpm

cdef extern from "math.h":
    double c_lgamma "lgamma" (double)
    double c_exp "exp" (double)

def exp(n):
    """Return e**n."""
    return c_exp(n)

def lfactorial(n):
    """Return an estimate of the log factorial of n."""
    return c_lgamma(n+1)

def factorial(n):
    """Return an estimate of the factorial of n."""
    return c_exp( c_lgamma(n+1) )


if __name__ == "__main__":
    import sys
    if len(sys.argv) != 2:
        sys.stderr.write("USAGE: %s n\nPrints n!.\n" % sys.argv[0])
        sys.exit(1)
    n = map(float, sys.argv[1:])
    print factorial(n)