Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 78c129e4a46a64625b53d61bd2b90fab > files > 342

python-cython-0.15-0.1mdv2010.2.i586.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(2)
    n, = map(float, sys.argv[1:])
    print factorial(n)