public static double HighAccuracyComplemented ( double x ) { double [ ] R = { 1.25331413731550025 , 0.421369229288054473 , 0.236652382913560671 , 0.162377660896867462 , 0.123131963257932296 , 0.0990285964717319214 , 0.0827662865013691773 , 0.0710695805388521071 , 0.0622586659950261958 } ; int j = ( int ) ( 0.5 * ( Math . abs ( x ) + 1 ) ) ; double a = R [ j ] ; double z = 2 * j ; double b = a * z - 1 ; double h = Math . abs ( x ) - z ; double q = h * h ; double pwr = 1 ; double sum = a + h * b ; double term = a ; for ( int i = 2 ; sum != term ; i += 2 ) { term = sum ; a = ( a + z * b ) / ( i ) ; b = ( b + z * a ) / ( i + 1 ) ; pwr *= q ; sum = term + pwr * ( a + h * b ) ; } sum *= Math . exp ( - 0.5 * ( x * x ) - 0.5 * Constants . Log2PI ) ; return ( x >= 0 ) ? sum : ( 1.0 - sum ) ; }
High - accuracy Complementary normal distribution function .