function ln_erfc(x)
  
!!! Abramowitz, Milton; Stegun, Irene A., eds. (1972), Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, New York: Dover Publications, ISBN 978-0-486-61272-0

  implicit none
  real, intent(in) :: x
  real :: ln_erfc
  real, parameter :: p = 0.3275911, a1 = 0.254829592, a2 = -0.284496736, a3 = 1.421413741, a4 = -1.453152027, &
       a5 = 1.061405429
  real :: t
  
  t = 1./(1.+p*abs(x))
  ln_erfc = log(a1*t + a2*t**2 + a3*t**3 + a4*t**4 + a5*t**5) - x**2
  if (x < 0) ln_erfc = log(2-exp(ln_erfc))
  
end function ln_erfc
