private static double erf_of_nonneg ( final double x ) { // The constants that appear below, formatted for easy checking against the book. // a1 = 0.07052 30784 // a3 = 0.00927 05272 // a5 = 0.00027 65672 // a2 = 0.04228 20123 // a4 = 0.00015 20143 // a6 = 0.00004 30638 final double a1 = 0.0705230784 ; final double a3 = 0.0092705272 ; final double a5 = 0.0002765672 ; final double a2 = 0.0422820123 ; final double a4 = 0.0001520143 ; final double a6 = 0.0000430638 ; final double x2 = x * x ; // x squared, x cubed, etc. final double x3 = x2 * x ; final double x4 = x2 * x2 ; final double x5 = x2 * x3 ; final double x6 = x3 * x3 ; final double sum = ( 1.0 + ( a1 * x ) + ( a2 * x2 ) + ( a3 * x3 ) + ( a4 * x4 ) + ( a5 * x5 ) + ( a6 * x6 ) ) ; final double sum2 = sum * sum ; // raise the sum to the 16th power final double sum4 = sum2 * sum2 ; final double sum8 = sum4 * sum4 ; final double sum16 = sum8 * sum8 ; return ( 1.0 - ( 1.0 / sum16 ) ) ; }
Abramowitz and Stegun formula 7 . 1 . 28 p . 88 ; Claims accuracy of about 7 decimal digits