NCEP CCS Conversion Guide
Issues Converting FORTRAN and C/C++ Programs
Back to Main Page
Topic: Floating Point Truncation/Rounding Differences
Posted by: Stephen Gilbert
Updated by
Post Date: 12/06/2002
Last Updated: 
Problem:   FORTRAN Programs that were compiled on asp/bsp without the "-qarch=auto", "-qarch=604" or "-qarch=pwr3"
                   option were, by default, compiled with "-qarch=com" which forces all floating point calculations to be performed with
                   64-bit precision.  The resulting values are truncated down to 32-bit floating point values when stored in a four byte
                   real variable. 

                   On Snow/Frost the default compiler option "-qarch=auto" is used, which takes advantage of hardware to
                    perform floating point operations with 32-bit precision for four byte real varaibles.  This difference can cause
                    a program to output slightly different results when recompiled and run on frost/snow.

Solution: 
      If the program is ouputting slightly different results when run on frost/snow, try recompiling and rerunning on asp/bsp
      using the "-qarch=auto" option.  If the program now produces the same results as frost/snow, then the differences are
      likely due to the floating point precision being used.  If the results still don't match those produced on snow/frost, then
      something else is going on, and more investigation is needed.

Caveats: 

Example:

             Consider the following Fortran statement intended to combine the year, month, day and hour into 
             one 10 digit integer of the form YYYYMMDDHH:
 
           IDATE =IYEAR*1E6 + IMONTH*1E4 + IDAY*1E2 + IHOUR

             The 1E6, 1E4 and 1E2 real constants force this calculation to be done using floating point arithmetic.  If this
             compiled with "-qarch=com", 64-bit floating point calculations are used and the resulting integer date is
             expected value.  However, on frost/snow ( -qarch=auto ) this calculation is attempted with 32-bit floating
             arithmetic, which cannot accurately represent this number, and an incorrect date is stored in IDATE.
 

Back to Main Page