r1mach Function

public pure function r1mach(i)

Return floating point (single precision) machine dependent constants.

R1MACH can be used to obtain machine-dependent parameters for the local machine environment. It is a function subprogram with one (input) argument, and can be referenced as follows:

  A = R1MACH(I)

where I=1,...,5. The (output) value of A above is determined by the (input) value of I. The results for various values of I are discussed below.

  • R1MACH(1) = B**(EMIN-1), the smallest positive magnitude.
  • R1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.
  • R1MACH(3) = B**(-T), the smallest relative spacing.
  • R1MACH(4) = B**(1-T), the largest relative spacing.
  • R1MACH(5) = LOG10(B)

Assume single precision numbers are represented in the T-digit, base-B form

  sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )

  where 0 <= X(I) < B for I=1,...,T, 0 < X(1), and
  EMIN <= E <= EMAX.

The values of B, T, EMIN and EMAX are provided in i1mach as follows:

  • I1MACH(10) = B, the base.
  • I1MACH(11) = T, the number of base-B digits.
  • I1MACH(12) = EMIN, the smallest exponent E.
  • I1MACH(13) = EMAX, the largest exponent E.

Author

  • Fox, P. A., (Bell Labs)
  • Hall, A. D., (Bell Labs)
  • Schryer, N. L., (Bell Labs)

Revision history

  • 790101 DATE WRITTEN
  • 960329 Modified for Fortran 90 (BE after suggestions by EG)
  • 220619 Modified for Fortran 2008 (JW)

Arguments

TypeIntentOptionalAttributesName
integer, intent(in) :: i

Return Value real(kind=sp)


Contents

Source Code


Source Code

   pure real(sp) function r1mach(i)

      integer, intent(in) :: i

      real(sp), parameter :: x = 1.0_sp
      real(sp), parameter :: b = real(radix(x), sp)

      select case (i)
      case (1); r1mach = b**(minexponent(x) - 1) ! the smallest positive magnitude.
      case (2); r1mach = huge(x)                 ! the largest magnitude.
      case (3); r1mach = b**(-digits(x))         ! the smallest relative spacing.
      case (4); r1mach = b**(1 - digits(x))      ! the largest relative spacing.
      case (5); r1mach = log10(b)
      case default
         error stop 'Error in r1mach - i out of bounds'
      end select

   end function r1mach