R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > # macheps.s J F Monahan, June 2001 > # revised August 2007 > # compute machine epsilon > # > # first try some values to get in ballpark > eps <- 2**(-56) > "2**(-56)" [1] "2**(-56)" > eps [1] 1.387779e-17 > "Is 1+eps bigger 1 for eps = j*2**(-56), j = 1 to 16" [1] "Is 1+eps bigger 1 for eps = j*2**(-56), j = 1 to 16" > (1!=(1+eps*(1:16))) # F if different, T if not [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE > # > # at this point it's around 8*2**(-56) or 2**(-53) > # or ... 64*2**(-59), so try 60 to 70 > "Is 1+eps bigger 1 for eps = j*2**(-59), j = 60 to 70" [1] "Is 1+eps bigger 1 for eps = j*2**(-59), j = 60 to 70" > eps <- 2**(-59) > (1!=(1+eps*(60:70))) [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE > # > # another try > eps <- 2**(-53) # first guess + smaller > (1!=(1+eps*(1 + 2**(-1:-16)))) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE [13] FALSE FALSE FALSE FALSE > # this is different -- the real machine epsilon > "Is 1+eps bigger 1 for eps = 2**(-53) + 2**(-63)" [1] "Is 1+eps bigger 1 for eps = 2**(-53) + 2**(-63)" > eps <- 2**(-53) + 2**(-63) > eps [1] 1.111307e-16 > (1!=(1+eps)) [1] TRUE > # > # this is the same -- just a hair too small > "Is 1+eps bigger 1 for eps = 2**(-53) + 2**(-64)" [1] "Is 1+eps bigger 1 for eps = 2**(-53) + 2**(-64)" > eps <- 2**(-53) + 2**(-64) > (1!=(1+eps)) [1] FALSE > # > rm(list=ls()) >