Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(60)  |  Call(60)  |  Derive(0)  |  Import(0)

        def loggamma(x):
    if type(x) not in (float, complex):
        try:
            x = float(x)
        except (ValueError, TypeError):
            x = complex(x)
    try:
        xreal = x.real
        ximag = x.imag
    except AttributeError:   # py2.5
        xreal = x
        ximag = 0.0
    # Reflection formula
    # http://functions.wolfram.com/GammaBetaErf/LogGamma/16/01/01/0003/
    if xreal < 0.0:
        if abs(x) < 0.5:
            v = log(gamma(x))
            if ximag == 0:
                v = v.conjugate()
            return v
        z = 1-x
        try:
            re = z.real
            im = z.imag
        except AttributeError:   # py2.5
            re = z
            im = 0.0
        refloor = floor(re)
        if im == 0.0:
            imsign = 0
        elif im < 0.0:
            imsign = -1
        else:
            imsign = 1
        return (-pi*1j)*abs(refloor)*(1-abs(imsign)) + logpi - \
            log(sinpi(z-refloor)) - loggamma(z) + 1j*pi*refloor*imsign
    if x == 1.0 or x == 2.0:
        return x*0
    p = 0.
    while abs(x) < 11:
        p -= log(x)
        x += 1.0
    s = 0.918938533204672742 + (x-0.5)*log(x) - x
    r = 1./x
    r2 = r*r
    s += 0.083333333333333333333*r; r *= r2
    s += -0.0027777777777777777778*r; r *= r2
    s += 0.00079365079365079365079*r; r *= r2
    s += -0.0005952380952380952381*r; r *= r2
    s += 0.00084175084175084175084*r; r *= r2
    s += -0.0019175269175269175269*r; r *= r2
    s += 0.0064102564102564102564*r; r *= r2
    s += -0.02955065359477124183*r
    return s + p
        


src/s/y/sympy-0.7.5/sympy/mpmath/tests/test_fp.py   sympy(Download)
    assert ae(fp.fac(-3.5), -0.94530872048294188123)
    assert ae(fp.fac(2+3j), (-0.44011340763700171113 - 0.06363724312631702183j))
    assert ae(fp.loggamma(1.0), 0.0)
    assert ae(fp.loggamma(2.0), 0.0)
    assert ae(fp.loggamma(3.0), 0.69314718055994530942)
    assert ae(fp.loggamma(7.25), 7.0521854507385394449)
    assert ae(fp.loggamma(1000.0), 5905.2204232091812118)

src/s/y/sympy-HEAD/sympy/mpmath/tests/test_fp.py   sympy(Download)
    assert ae(fp.fac(-3.5), -0.94530872048294188123)
    assert ae(fp.fac(2+3j), (-0.44011340763700171113 - 0.06363724312631702183j))
    assert ae(fp.loggamma(1.0), 0.0)
    assert ae(fp.loggamma(2.0), 0.0)
    assert ae(fp.loggamma(3.0), 0.69314718055994530942)
    assert ae(fp.loggamma(7.25), 7.0521854507385394449)
    assert ae(fp.loggamma(1000.0), 5905.2204232091812118)

src/s/y/sympy-polys-HEAD/sympy/mpmath/tests/test_fp.py   sympy-polys(Download)
    assert ae(fp.fac(-3.5), -0.94530872048294188123)
    assert ae(fp.fac(2+3j), (-0.44011340763700171113 - 0.06363724312631702183j))
    assert ae(fp.loggamma(1.0), 0.0)
    assert ae(fp.loggamma(2.0), 0.0)
    assert ae(fp.loggamma(3.0), 0.69314718055994530942)
    assert ae(fp.loggamma(7.25), 7.0521854507385394449)
    assert ae(fp.loggamma(1000.0), 5905.2204232091812118)