My approach using a look-up table.
! test erfc by dumping values into a spreadsheet
!
real8 random, erfc, x, y
integer4 i
external random, erfc
!
do i = 1,10000
x = random () * 3.0
y = erfc (x)
write (,) i,x,y
end do
end
real*8 function erfc (x)
!
! calculate the value of erfc for x using a quadratic lookup table for x in the range 0:6
! use table of ln(erfc(x)) as this is closer to quadratic variation
!
real*8 x
!
real*8 quadratic_function, y
external quadratic_function ! (x, table, x0, dx, n)
real*8 x0, dx, log_erfc_table(-1:120)
integer*4 n
!
data n, x0, dx / 120, 0, 0.05 /
!
! look up table for ln(erfc(x)) in steps of 0.05
data log_erfc_table / & ! ln(erfc.precise(x)) from excel_2010
0.054840375, 0, & ! -0.05, 0
-0.058023235, -0.119304974, & ! 0.1
-0.183917996, -0.251932234, & ! 0.2
-0.323414803, -0.398430051, & ! 0.3
-0.47703961, -0.559302458, & ! 0.4
-0.645274999, -0.73501113, & ! 0.5
-0.828562327, -0.925977727, & ! 0.6
-1.027304216, -1.132586514, & ! 0.7
-1.241867261, -1.355187107, & ! 0.8
-1.472584795, -1.594097247, & ! 0.9
-1.719759644, -1.84960551, & ! 1
-1.983666787, -2.121973911, & ! 1.1
-2.264555887, -2.411440355, & ! 1.2
-2.562653662, -2.718220922, & ! 1.3
-2.878166081, -3.042511975, & ! 1.4
-3.211280384, -3.38449209, & ! 1.5
-3.562166921, -3.744323809, & ! 1.6
-3.930980826, -4.122155234, & ! 1.7
-4.317863525, -4.51812146, & ! 1.8
-4.722944103, -4.932345863, & ! 1.9
-5.146340521, -5.364941265, & ! 2
-5.588160718, -5.816010969, & ! 2.1
-6.048503596, -6.285649693, & ! 2.2
-6.527459896, -6.773944403, & ! 2.3
-7.025112994, -7.280975056, & ! 2.4
-7.541539599, -7.806815273, & ! 2.5
-8.076810388, -8.351532931, & ! 2.6
-8.630990575, -8.915190702, & ! 2.7
-9.20414041, -9.497846531, & ! 2.8
-9.796315639, -10.09955407, & ! 2.9
-10.40756791, -10.72036304, & ! 3
-11.03794513, -11.36031963, & ! 3.1
-11.68749181, -12.01946675, & ! 3.2
-12.35624936, -12.69784435, & ! 3.3
-13.04425632, -13.39548966, & ! 3.4
-13.75154865, -14.1124374, & ! 3.5
-14.47815991, -14.84872003, & ! 3.6
-15.22412149, -15.60436789, & ! 3.7
-15.98946274, -16.37940941, & ! 3.8
-16.77421118, -17.17387122, & ! 3.9
-17.5783926, -17.98777831, & ! 4
-18.40203124, -18.82115418, & ! 4.1
-19.24514986, -19.67402092, & ! 4.2
-20.1077699, -20.5463993, & ! 4.3
-20.98991154, -21.43830894, & ! 4.4
-21.89159379, -22.3497683, & ! 4.5
-22.81283463, -23.28079485, & ! 4.6
-23.753651, -24.23140506, & ! 4.7
-24.71405894, -25.20161453, & ! 4.8
-25.69407363, -26.19143803, & ! 4.9
-26.69370944, -27.20088955, & ! 5