[R] runif limited precision
Stavros Macrakis
macrakis at alum.mit.edu
Fri Jan 2 20:45:28 CET 2009
runif appears to give 31 bits of precision, but this isn't mentioned
in the documentation page. The R numeric type supports 53 digits of
precision, and other numeric functions (sin, etc.) give full-precision
results. So I'd think that either runif should give full precision or
its documentation should mention this limitation.
#integers
table(runif(10000,-2^30,2^30) %% 1)
0 0.5
4972 5028
#natural numbers
> table(runif(10000,0,2^31) %% 1)
0 0.5
4956 5044
#fractions
table((r<-runif(10000,0,1)*2^31)-floor(r))
0 0.5
5021 4979
More information about the R-help
mailing list