Gamma { public static double invGamma1pm1(final double x) { if (x < -0.5) { throw new NumberIsTooSmallException(x, -0.5, true); } if (x > 1.5) { throw new NumberIsTooLargeException(x, 1.5, true); } final double ret; final double t = x <= 0.5 ? x : (x - 0.5) - 0.5; if (t < 0.0) { final double a = INV_GAMMA1P_M1_A0 + t * INV_GAMMA1P_M1_A1; double b = INV_GAMMA1P_M1_B8; b = INV_GAMMA1P_M1_B7 + t * b; b = INV_GAMMA1P_M1_B6 + t * b; b = INV_GAMMA1P_M1_B5 + t * b; b = INV_GAMMA1P_M1_B4 + t * b; b = INV_GAMMA1P_M1_B3 + t * b; b = INV_GAMMA1P_M1_B2 + t * b; b = INV_GAMMA1P_M1_B1 + t * b; b = 1.0 + t * b; double c = INV_GAMMA1P_M1_C13 + t * (a / b); c = INV_GAMMA1P_M1_C12 + t * c; c = INV_GAMMA1P_M1_C11 + t * c; c = INV_GAMMA1P_M1_C10 + t * c; c = INV_GAMMA1P_M1_C9 + t * c; c = INV_GAMMA1P_M1_C8 + t * c; c = INV_GAMMA1P_M1_C7 + t * c; c = INV_GAMMA1P_M1_C6 + t * c; c = INV_GAMMA1P_M1_C5 + t * c; c = INV_GAMMA1P_M1_C4 + t * c; c = INV_GAMMA1P_M1_C3 + t * c; c = INV_GAMMA1P_M1_C2 + t * c; c = INV_GAMMA1P_M1_C1 + t * c; c = INV_GAMMA1P_M1_C + t * c; if (x > 0.5) { ret = t * c / x; } else { ret = x * ((c + 0.5) + 0.5); } } else { double p = INV_GAMMA1P_M1_P6; p = INV_GAMMA1P_M1_P5 + t * p; p = INV_GAMMA1P_M1_P4 + t * p; p = INV_GAMMA1P_M1_P3 + t * p; p = INV_GAMMA1P_M1_P2 + t * p; p = INV_GAMMA1P_M1_P1 + t * p; p = INV_GAMMA1P_M1_P0 + t * p; double q = INV_GAMMA1P_M1_Q4; q = INV_GAMMA1P_M1_Q3 + t * q; q = INV_GAMMA1P_M1_Q2 + t * q; q = INV_GAMMA1P_M1_Q1 + t * q; q = 1.0 + t * q; double c = INV_GAMMA1P_M1_C13 + (p / q) * t; c = INV_GAMMA1P_M1_C12 + t * c; c = INV_GAMMA1P_M1_C11 + t * c; c = INV_GAMMA1P_M1_C10 + t * c; c = INV_GAMMA1P_M1_C9 + t * c; c = INV_GAMMA1P_M1_C8 + t * c; c = INV_GAMMA1P_M1_C7 + t * c; c = INV_GAMMA1P_M1_C6 + t * c; c = INV_GAMMA1P_M1_C5 + t * c; c = INV_GAMMA1P_M1_C4 + t * c; c = INV_GAMMA1P_M1_C3 + t * c; c = INV_GAMMA1P_M1_C2 + t * c; c = INV_GAMMA1P_M1_C1 + t * c; c = INV_GAMMA1P_M1_C0 + t * c; if (x > 0.5) { ret = (t / x) * ((c - 0.5) - 0.5); } else { ret = x * c; } } return ret; } private  Gamma(); static double logGamma(double x); static double regularizedGammaP(double a, double x); static double regularizedGammaP(double a,
                                           double x,
                                           double epsilon,
                                           int maxIterations); static double regularizedGammaQ(double a, double x); static double regularizedGammaQ(final double a,
                                           double x,
                                           double epsilon,
                                           int maxIterations); static double digamma(double x); static double trigamma(double x); static double lanczos(final double x); static double invGamma1pm1(final double x); static double logGamma1p(final double x); static double gamma(final double x); static final double GAMMA; static final double LANCZOS_G; }
@Test public void testInvGamma1pm1() { final int ulps = 3; for (int i = 0; i < INV_GAMMA1P_M1_REF.length; i++) { final double[] ref = INV_GAMMA1P_M1_REF[i]; final double x = ref[0]; final double expected = ref[1]; final double actual = Gamma.invGamma1pm1(x); final double tol = ulps * FastMath.ulp(expected); Assert.assertEquals(Double.toString(x), expected, actual, tol); } }
@Test(expected = NumberIsTooSmallException.class) public void testInvGamma1pm1Precondition1() { Gamma.invGamma1pm1(-0.51); }
@Test(expected = NumberIsTooLargeException.class) public void testInvGamma1pm1Precondition2() { Gamma.invGamma1pm1(1.51); }