d1mach revisited: no more uncommenting DATA statements

Presented at the IFIP WG 2.5 International Workshop on "Current Directions in Numerical Software and High Performance Computing", 19 - 20 October 1995, Kyoto, Japan.

David Gay and Eric Grosse

David Gay, dmg@bell-labs.com
Bell Laboratories 2C-463
700 Mountain Avenue
Murray Hill, New Jersey 07974-0636

Eric Grosse, ehg@bell-labs.com
Bell Laboratories 2T-504
700 Mountain Avenue
Murray Hill, New Jersey 07974-0636

Summary written by Bo Einarsson

Bo Einarsson, boein@nsc.liu.se
National Supercomputer Centre
Linköping University


  1. Introduction
  2. Previous Realization Fortran 66
  3. Previous Realization Fortran 77
  4. Present Realization Fortran 77
  5. Present Realization Fortran 90
  6. References

1. Introduction.

The routines r1mach and d1mach were written in 1978 with the purpose to return floating point machine dependent constants in order to provide portability through changing only the three routines r1mach (for floating point numbers), d1mach (for floating point numbers in double precision), and i1mach (for integers).

The authors were all from Bell Labs: P. A. Fox, A. D. Hall and N. L. Schryer (June 1978).

C   R1MACH can be used to obtain machine-dependent parameters for the
C   local machine environment.  It is a function subprogram with one
C   (input) argument, and can be referenced as follows:
C        A = R1MACH(I)
C   where I=1,...,5.  The (output) value of A above is determined by
C   the (input) value of I.  The results for various values of I are
C   discussed below.
C   R1MACH(1) = B**(EMIN-1), the smallest positive magnitude.
C   R1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.
C   R1MACH(3) = B**(-T), the smallest relative spacing.
C   R1MACH(4) = B**(1-T), the largest relative spacing.
C   R1MACH(5) = LOG10(B)
Similar descriptions exist for d1mach and i1mach.

2. Previous Realization (Fortran 66)

The first realization consisted of three programs with a long list of commented data statements, where it was left to the the user to select the set of five lines (for r1mach) which applied to his/her system and uncomment those lines.

Also d1mach has five lines, while i1mach has as many as 16 lines for each system.

Some of the integer parameters, like unit number of the punching unit, are now obsolete.

The routines r1mach.f, d1mach.f, and i1mach.f are nowadays available (with parameters for most systems) from netlib in the library slatec/src/.

3. Previous Realization (Fortran 77)

More modern and convenient versions r1mach.f, d1mach.f, and i1mach.f are available in netlib/port/, which automatically choose the right constants for some common environments (IEEE, VAX, IBM mainframe, Cray). Since Fortran 90 is supposed to be upward compatible with Fortran 77, these improved routines should work fine under Fortran 90, at least in the above common environments. (Does anyone use anything else these days?)

4. Present Realization (Fortran 77)

Even more modern and convenient versions r1mach.f, d1mach.f, and i1mach.f are available in netlib/blas/, see David Gay and Eric Grosse (August 1996, revised July 1998).

5. Present Realization (Fortran 90)

The original routines have been modified to use the intrinsic functions available in Fortran 90. This was not completely possible with i1mach, since that one includes some parameters of a different nature, like I1MACH(3), which is the unit number for the punch unit.

The error message unit I1MACH(4) is usually 0 in UNIX systems.

The parameter I1MACH(6) is the number of characters per integer storage unit and applies to Fortran 66, where Hollerith characters were stored in integer variables (or even worse, in floating point variables). It was put to "1" for for the Fortran 77 versions of the Port error-handling routines to work correctly. Since the two Port routines e9rint and seterr now have been modified, the more relevant value I1MACH(6) = 4 is used. It is valid at least for all IEEE based computers, where a Fortran integer occupies 4 bytes.

The routines r1mach.f90, d1mach.f90, and i1mach.f90 are available here.

Also a set of very simple test programs have been made available, they show the hexadecimal values obtained. These values can be compared with the values from the older versions. The test programs are test_of_r1mach.f90, test_of_d1mach.f90, and test_of_i1mach.f90.

In April 1999 a new set of test programs were prepared. These are closer to Fortran 77, they print the floating point values and not only the hexadecimal values, and are intended to be more system-independent than the old ones. The new ones however fail to print the hexadecimal values with the NAG compiler and on the Cray C90 in double precision. The new test programs are test2_of_r1mach.f90 and test2_of_d1mach.f90.

6. References

P. A. Fox, A. D. Hall and N. L. Schryer, Framework for a portable library, ACM Transactions on Mathematical Software 4, 2 (June 1978), pp. 177-188.

David Gay and Eric Grosse, Self-Adapting Fortran 77 Machine Constants: Comment on Algorithm 528, ACM Transactions on Mathematical Software 25, 1 (March 1999), pp. 123-126.

Last modified: 19 July 1999