safe_sqrt Function

private elemental function safe_sqrt(arg)

A wrapper to sqrt which replaces -ve values with 0.0 to avoid NaNs arising from slight floating point discrepancies. We could consider adding a debug check to abort/warn if the passed value is too negative (i.e. if it looks like an error rather than small round off).

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: arg

Return Value real


Contents

Source Code


Source Code

  elemental real function safe_sqrt(arg)
    implicit none
    real, intent(in) :: arg
    safe_sqrt = sqrt(max(0.0, arg))
  end function safe_sqrt