d1mach <- function ( i ) #*****************************************************************************80 # ## D1MACH returns double precision real machine constants. # # Discussion: # # Assume that double precision real numbers are stored with a mantissa # of T digits in base B, with an exponent whose value must lie # between EMIN and EMAX. Then for values of I between 1 and 5, # D1MACH will return the following values: # # D1MACH(1) <- B^(EMIN-1), the smallest positive magnitude. # D1MACH(2) <- B^EMAX*(1-B^(-T)), the largest magnitude. # D1MACH(3) <- B^(-T), the smallest relative spacing. # D1MACH(4) <- B^(1-T), the largest relative spacing. # D1MACH(5) <- log10(B) # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 05 February 2020 # # Author: # # Original FORTRAN77 version by Phyllis Fox, Andrew Hall, Norman Schryer # R version by John Burkardt. # # Reference: # # Phyllis Fox, Andrew Hall, Norman Schryer, # Algorithm 528, # Framework for a Portable Library, # ACM Transactions on Mathematical Software, # Volume 4, Number 2, June 1978, page 176-188. # # Input: # # integer I, chooses the parameter to be returned. # 1 <= I <= 5. # # Output: # # real VALUE, the value of the chosen parameter. # { if ( i < 1 ) { cat ( "\n" ) cat ( "D1MACH - Fatal error!\n" ) cat ( " The input argument I is out of bounds.\n" ) cat ( " Legal values satisfy 1 <= I <= 5.\n" ) cat ( " I <- ", i ) stop ( "D1MACH - Fatal error!\n" ) } else if ( i == 1 ) { value <- .Machine$double.xmax } else if ( i == 2 ) { value <- .Machine$double.xmin } else if ( i == 3 ) { value <- .Machine$double.eps / 2.0 } else if ( i == 4 ) { value <- .Machine$double.eps } else if ( i == 5 ) { value <- log10 ( .Machine$double.base ) } else if ( 5 < i ) { cat ( "\n" ) cat ( "D1MACH - Fatal error!\n" ) cat ( " The input argument I is out of bounds.\n" ) cat ( " Legal values satisfy 1 <= I <= 5.\n" ) cat ( " I <- ", i ) stop ( "D1MACH - Fatal error!" ) } return ( value ) }