Functions { public static double zeta(double x, double q) { if(x == 1.0) return Double.POSITIVE_INFINITY; if(q < 1.0) return Double.NaN; if(q <= 0.0) if(q == floor(q)) return Double.POSITIVE_INFINITY; else return Double.NaN; double s = pow(q, -x); double a = q; double b = 0.0; int i = 0; boolean done = false; while( (i < 9 || a <= 9.0) && ! done) { i++; a++; b = pow(a, -x); s += b; if(abs(b/s) < EPSILON) done = true; } double k = 0.0; double w = a; s += b * w / (x - 1.0); s -= 0.5 * b; a = 1.0; double t; for(i = 0; i < 12 && ! done; i ++) { a *= x + k; b /= w; t = a * b / m[i]; s += t; t = abs(t/s); if(t < EPSILON) done = true; k += 1.0; a *= x + k; b /= w; k += 1.0; } return s; }  static double zeta(double x, double q); static double zeta(double s); static double polynomial(double x, double[] coefficients); static List<T> unique(Collection<T> data); static Logger log(); static double mean(List<? extends Number> values); static double standardDeviation(List<? extends Number> values);  }
@Test public void testZeta() { assertEquals(1.64493406684822, zeta(2.0, 1.0), 10E-12); assertEquals(0.13182783346272, zeta(3.456, 2.0), 10E-12); assertEquals(1.55869618375063E-26, zeta(20.0, 20.0), 10E-12); }
@Test public void testZetaSingle() { assertEquals(1.64493406684822, zeta(2.0), 10E-12); assertEquals(1.13182783346272, zeta(3.456), 10E-12); assertEquals(1.00000089006735, zeta(20.1), 10E-12); assertEquals(2.61237534868548, zeta(1.5), 10E-12); assertEquals(1.34148725725091, zeta(2.5), 10E-12); assertEquals(1.18338365211190, zeta(3.1), 10E-12); }