Erf { public static double erfc(double x) { if (FastMath.abs(x) > 40) { return x > 0 ? 0 : 2; } final double ret = Gamma.regularizedGammaQ(0.5, x * x, 1.0e-15, 10000); return x < 0 ? 2 - ret : ret; } private  Erf(); static double erf(double x); static double erfc(double x); static double erf(double x1, double x2); static double erfInv(final double x); static double erfcInv(final double x);  }
@Test public void testErfcGnu() { final double tol = 1E-15; final double[] gnuValues = new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 1.9999999999999999785, 1.9999999999999926422, 1.9999999999984625402, 1.9999999998033839558, 1.9999999845827420998, 1.9999992569016276586, 1.9999779095030014146, 1.9995930479825550411, 1.9953222650189527342, 1.9661051464753107271, 1.8427007929497148695, 1.5204998778130465381, 1, 0.47950012218695346194, 0.15729920705028513051, 0.033894853524689272893, 0.0046777349810472658333, 0.00040695201744495893941, 2.2090496998585441366E-05, 7.4309837234141274516E-07, 1.5417257900280018858E-08, 1.966160441542887477E-10, 1.5374597944280348501E-12, 7.3578479179743980661E-15, 2.1519736712498913103E-17, 3.8421483271206474691E-20, 4.1838256077794144006E-23, 2.7766493860305691016E-26, 1.1224297172982927079E-29, 2.7623240713337714448E-33, 4.1370317465138102353E-37, 3.7692144856548799402E-41, 2.0884875837625447567E-45}; double x = -10d; for (int i = 0; i < 41; i++) { Assert.assertEquals(gnuValues[i], Erf.erfc(x), tol); x += 0.5d; } }
@Test public void testErfcMaple() { double[][] ref = new double[][] {{0.1, 4.60172162722971e-01}, {1.2, 1.15069670221708e-01}, {2.3, 1.07241100216758e-02}, {3.4, 3.36929265676881e-04}, {4.5, 3.39767312473006e-06}, {5.6, 1.07175902583109e-08}, {6.7, 1.04209769879652e-11}, {7.8, 3.09535877195870e-15}, {8.9, 2.79233437493966e-19}, {10.0, 7.61985302416053e-24}, {11.1, 6.27219439321703e-29}, {12.2, 1.55411978638959e-34}, {13.3, 1.15734162836904e-40}, {14.4, 2.58717592540226e-47}, {15.5, 1.73446079179387e-54}, {16.6, 3.48454651995041e-62} }; for (int i = 0; i < 15; i++) { final double result = 0.5*Erf.erfc(ref[i][0]/FastMath.sqrt(2)); Assert.assertEquals(ref[i][1], result, 1E-15); TestUtils.assertRelativelyEquals(ref[i][1], result, 1E-13); } }