3

I am working on re-engineering an old FORTRAN77 program to Python for a while now. I'm running into an issue, though: when dividing by zero, it appears that the FORTRAN program just continues processing the data without issue. However, predictably it causes an issue in Python. I'm not able to find a discussion about this on any official channel for F77, and I only have an old version of the source code for the program I am translating that I can't get to compile.

TL;DR: How does F77 handle division by zero for the following cases?:

  1. REAL division
  2. INT division
  3. The numerator is also zero (e.g. 0./0.)
francescalus
  • 30,576
  • 16
  • 61
  • 96
Dakota B
  • 138
  • 9
  • 4
    Do you care about the behaviour under Fortran 77 specifically or as the code would be treated by a compiler released more recently over the last thirty years? – francescalus Dec 01 '19 at 11:03
  • 3
    That depends on many details. What platform was your code made for? Which compiler? Which compiler settings? Python can continue as well, just treat the exceptions or disable them. – Vladimir F Героям слава Dec 01 '19 at 13:48
  • The code was last compiled on Windows Vista with what looks to be Visual Studio (.mdp file) in 2008. – Dakota B Dec 02 '19 at 05:38
  • 1
    If it uses .mdp files, it would have been compiled under Powerstation4. Powerstation4 came out in 1993. The modern version of this is the Intel compiler. – cup Dec 12 '19 at 10:51
  • All the Fortrans I've ever used would throw an exeception (stack dump) on divide by zero. – Mark Diaz Mar 10 '20 at 03:13

1 Answers1

2

Yes, I also have code that does nothing when a divide by zero error is encountered. Usually, it is the programmers responsibility to ensure that the results are either expected (the target variable's value is unchanged) or an error is thrown etc. In other words, you need to inspect any division operation for a possible zero divisor. Modern operating systems throw an internal exception on divide by zero (and assign NAN to the target variable if the system would pause under these circumstances), most older Fortran code is written such that divide by zero doesn't matter.