SICOPOLIS V3.0
 All Classes Files Functions Variables Macros
erfcc.F90
Go to the documentation of this file.
1 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 !
3 ! Function : e r f c c
4 !
5 !> @file
6 !!
7 !! Computation of the complementary error function erfc(x) = 1-erf(x)
8 !! with a fractional error everywhere less than 1.2 x 10^(-7)
9 !! (formula by Press et al., 'Numerical Recipes in Fortran 77').
10 !!
11 !! @section Copyright
12 !!
13 !! Copyright 2009-2013 Reinhard Calov, Ralf Greve
14 !!
15 !! @section License
16 !!
17 !! This file is part of SICOPOLIS.
18 !!
19 !! SICOPOLIS is free software: you can redistribute it and/or modify
20 !! it under the terms of the GNU General Public License as published by
21 !! the Free Software Foundation, either version 3 of the License, or
22 !! (at your option) any later version.
23 !!
24 !! SICOPOLIS is distributed in the hope that it will be useful,
25 !! but WITHOUT ANY WARRANTY; without even the implied warranty of
26 !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 !! GNU General Public License for more details.
28 !!
29 !! You should have received a copy of the GNU General Public License
30 !! along with SICOPOLIS. If not, see <http://www.gnu.org/licenses/>.
31 !<
32 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 
34 !-------------------------------------------------------------------------------
35 !> Computation of the complementary error function erfc(x) = 1-erf(x)
36 !! with a fractional error everywhere less than 1.2 x 10^(-7)
37 !! (formula by Press et al., 'Numerical Recipes in Fortran 77').
38 !<------------------------------------------------------------------------------
39 function erfcc(x)
40 
41 use sico_types
42 
43 implicit none
44 real(dp) :: erfcc
45 real(dp), intent(in) :: x
46 
47 real(dp) :: t, z
48 
49 z = abs(x)
50 t = 1.0_dp/(1.0_dp+0.5_dp*z)
51 
52 erfcc = t * exp( -z*z -1.26551223_dp &
53  + t * ( 1.00002368_dp &
54  + t * ( 0.37409196_dp &
55  + t * ( 0.09678418_dp &
56  + t * ( -0.18628806_dp &
57  + t * ( 0.27886807_dp &
58  + t * ( -1.13520398_dp &
59  + t * ( 1.48851587_dp &
60  + t * ( -0.82215223_dp &
61  + t * 0.17087277_dp ) ) ) ) ) ) ) ) )
62 
63 if (x < 0.0_dp) erfcc = 2.0_dp-erfcc
64 
65 end function erfcc
66 !