Compute error function erf(x)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x |
Argument of |
||
| real(kind=wp), | intent(out) | :: | Err |
|
subroutine error(x,Err) real(wp),intent(in) :: x !! Argument of `erf(x)` real(wp),intent(out) :: Err !! `erf(x)` real(wp) :: c0 , er , r , x2 integer :: k real(wp),parameter :: eps = 1.0e-15_wp x2 = x*x if ( abs(x)<3.5_wp ) then er = 1.0_wp r = 1.0_wp do k = 1 , 50 r = r*x2/(k+0.5_wp) er = er + r if ( abs(r)<=abs(er)*eps ) exit enddo c0 = 2.0_wp/sqrtpi*x*exp(-x2) Err = c0*er else er = 1.0_wp r = 1.0_wp do k = 1 , 12 r = -r*(k-0.5_wp)/x2 er = er + r enddo c0 = exp(-x2)/(abs(x)*sqrtpi) Err = 1.0_wp - c0*er if ( x<0.0_wp ) Err = -Err endif end subroutine error