[Rcpp-devel] Getting the exact arithmetic as in R when Rcpp is used?
Dirk Eddelbuettel
edd at debian.org
Tue Jul 9 08:57:34 CEST 2013
On 8 July 2013 at 06:51, Peng Yu wrote:
| > vx=rep(.1, 10)
| > options(digits=22)
| > fun(vx)
| [1] 0.9999999999999998889777
You are printing a data type that has around 16 decimals precision with 22.
That is bound to show random stuff at the end.
Otherwise, Bill is quite right that one can (and R Core does) use 'long
double' in the internal parts of loops which could otherwise accumulate
numerical error. There are many texts on numerical computing which cover
this. A short and classic paper by David Goldbergs is available in many
places under 'what ever computer scientist should know about floating-point
arithmetic'.
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list