Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[FORTRAN] Division by zero allowed?

  1. Oct 29, 2012 #1
    Hi, I have an issue where I am squaring a very small complex number 1e-20 (FALFA2) which seems to make the value zero (both the real and imag part) and then dividing by it, the problem line is (all the numbers are complex):
    GALFA = ( FBETA * FAA / FALFA2 ) - ( FAB / FALFA )

    I get the error 'unknown floating point exception'. However, when another compiler compiled this code the executable works fine and I don't get an error for this (this is an old code that I am making some edits to now). Is there a way to just let GALFA=INF or something and continue, or do whatever the other compiler did (whatever that is)? Thank you!
     
  2. jcsd
  3. Oct 29, 2012 #2
    Do the calculation in double precision.
     
  4. Oct 29, 2012 #3
    How exactly do I do that?
     
  5. Oct 29, 2012 #4
    double precision or quadruple!

    Different compilers do behave slightly different, by default, and there may be a way to control their behavior, too...you may want to read the user's manual for your compiler. I know that with g95, for example, one can set an environment variable to let the program continue or terminate on a "divide by zero" error.

    I seem to recall seeing IEEE related function calls to control reporting this problems and behavior.

    You can turn a blind eye and let the program continue, but what's the point? are you going to believe the results on a run like that?.

    Or

    ...fix the program and guard against things like this...what is the order of magnitude of your numbers? when is a zero, zero?

    Can you scale your problem and work with larger numbers?
     
  6. Oct 29, 2012 #5
    tell which compiler you are using

    post the commands you are using to compile the program
     
  7. Oct 29, 2012 #6
    Hi Gsal,

    I am using silverfrost (ftn95), and I am not really using any commands I just click 'compile'. And yes, I would just like to turn a blind eye. As I said, I have the executable that is the exact same code and it works fine, I just need to add a few write/print statements, but due to this issue I get the error I described.
     
  8. Oct 30, 2012 #7
    Oh, boy....that is dangerous.

    First you need a bit of help and you need to be willing to be a bit more diligent about this...nothing good can come out of turning a blind eye...maybe this task is in the wrong hands.

    Second, I don't use Silverfrost, so, I cannot give details. Hopefully somebody will come along and give you step-by-step instructions on how to find out what the compilation command being used is and how to tweak it...OR, you could investigate yourself.

    Good luck.
     
  9. Oct 30, 2012 #8
    Check your FORTRAN manual.
     
  10. Oct 30, 2012 #9

    rcgldr

    User Avatar
    Homework Helper

    My guess is that the older compiler uses higher precision floating point math, ending up dividing by a small number instead of zero. A similar thing happened with microsoft c. The old 16 bit compilers supported "long double" using the 80 bit format, but the 32/64 bit compilers changed this so that "long double" is the same as "double" at 64 bit format (perhaps an issue related to a win32 console mode program, but assembly code can still use the 80 bit format).
     
    Last edited: Oct 30, 2012
  11. Oct 30, 2012 #10

    uart

    User Avatar
    Science Advisor

    Just guessing here, but FALFA2 = FALFA*FALFA. Is that right? In that case you'd be much better off rearranging the calculation as :

    GALFA = ( FBETA * FAA / FALFA - FAB ) / FALFA
     
  12. Oct 30, 2012 #11
    I was able to get around this by using a different compiler (g95), thank you everyone for the help!
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook




Loading...
Similar Threads for FORTRAN Division zero Date
If statement for Monte Carlo integration Sunday at 7:46 AM
C/++/# How to use C++ in studying calculus Apr 3, 2018
Fortran How to buy Fortran Programming Software Commersial License Jan 30, 2018
Fortran Fortran for Computational Fluid Dynamics Problems Jan 11, 2018
Reed Solomon Division Aug 2, 2017