Hi Given a real number x, I want to know how accurately R can represent numbers near x. In particular, I want to know the infinum of exactly representable numbers greater than x, and the supremum of exactly representable numbers less than x. And then the interesting thing is the difference between these two. I have a little function that does some of this: f <- function(x,FAC=1.1){ delta <- x while(x+delta > x){ delta <- delta/FAC } return(delta*FAC) } But this can't be optimal. Is there a better way? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
Robin Hankin said the following on 9/11/2006 3:52 AM:> Hi > > Given a real number x, I want to know how accurately R can represent > numbers near x. > > In particular, I want to know the infinum of exactly representable > numbers greater than x, and the supremum of exactly representable > numbers > less than x. And then the interesting thing is the difference > between these two. > > > I have a little function that does some of this: > > > f <- function(x,FAC=1.1){ > delta <- x > while(x+delta > x){ > delta <- delta/FAC > } > return(delta*FAC) > } > > But this can't be optimal. > > Is there a better way? > > >I believe this is what .Machine$double.eps is. From ?.Machine double.eps: the smallest positive floating-point number 'x' such that '1 + x != 1'. It equals 'base^ulp.digits' if either 'base' is 2 or 'rounding' is 0; otherwise, it is '(base^ulp.digits) / 2'. See also .Machine$double.neg.eps. Is this what you need? --sundar