Help Files: Fortran77: Converting to Double Precision





     HELP                      June 15, 1985             F77/TO_DOUBLE



                  Converting Programs to Double Precision

     On VAXs, single precision provides about 6-7 digits  of  accuracy
     while  double  precision provides about 15-16 digits of accuracy.
     Many mathematical subroutine libraries  assume  double  precision
     arguments.

     To convert a program from single to double precision:


     1.   Add 'implicit double precision (a-h,o-z)' as the first  line
          of  the  main  program  (second line if you have a 'program'
          statement) and as the second line of all  other  subprograms
          (subroutines, functions, and block data subprograms).


     2.   Change all 'real' or 'real*4' declarations to 'double preci-
          sion'.


     3.   Change ALL single precision floating point constants to dou-
          ble  precision, either by adding 'd0' or changing an 'e' ex-
          ponent term to 'd', e.g.:
                          1.2    becomes 1.2d0
                          3.2e-5 becomes 3.2d-5


     4.   Change 'complex' or 'complex*8' declarations to 'double com-
          plex'.


     5.   Formats do not need to be changed.


     6.   Change single precision intrinsic functions to double.   Be-
          cause  of  the  generic function names in f77, the only ones
          you need to actually change are:

                  single version:         double or generic version:
                     ifix()                       int()
                     sngl()                       dble()
                     real()                       dble()
                     float()                      dble()
                     amax1()                      max()
                     amin1()                      min()
                     amod()                       mod()
                     alog()                       log()
                     alog10()                     log10()


     7.   Change complex intrinsic functions to double complex.

                  complex version:        double complex or generic version:
                     cmplx()                      dcmplx()
                     aimag()                      imag()
                     csqrt()                      sqrt()
                     cexp()                       exp()
                     clog()                       log()
                     ccos()                       cos()
                     csin()                       sin()
                     cabs()                       abs()


     8.   If you are passing functions as arguments to  other  subrou-
          tines,  you  need  to  change all function names to specific
          functions.  For example:

                          x1 = sqrt(x2)
                          z1 = abs(z2)

          works fine when x1 and x2 are double and z1 and z2 are  dou-
          ble complex.  However, if the computation is being done in a
          subroutine,

                          external sqrt, abs
                          call subr( x1, x2, sqrt, z1, z2, abs )

          they must be changed to:

                          external dsqrt, cdabs
                          call subr( x1, x2, dsqrt, z1, z2, cdabs )


     9.   Check equivalences common blocks, and dynamic memory alloca-
          tion.  Often these implicitly assume that floating point and
          integer values use the same amount of storage.  For example,
          if one subroutine declares:

                          common /abc/ key1,vec(5),ival,ans(5)

          and another declares:

                          common /abc/ dummy(6), ival, ans(5)

          then the two instances of 'ival' match.  If now  you  change
          'dummy',  'ans',  and  'vec' from single precision to double
          precision, the  two  instances  of  'ival'  will  no  longer
          correspond.


Comments to decf@euler.berkeley.edu
© 1998 UC Regents