Skip to content

Instantly share code, notes, and snippets.

@cvr
Created October 11, 2011 10:30
Show Gist options
  • Save cvr/1277782 to your computer and use it in GitHub Desktop.
Save cvr/1277782 to your computer and use it in GitHub Desktop.
Avoid possible division by zero by limiting the divisor (FORTRAN)
REAL, PARAMETER :: SMALL = 1.E-18
!! for a divisor b>0
c = a/MAX(b, SMALL)
!! for a divisor b with an arbitrary sign
c = a/SIGN(MAX(ABS(b), SMALL), b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment