-----Original Message-----
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-
bounces at lists.r-forge.r-project.org] On Behalf Of Peng Yu
Sent: Monday, July 08, 2013 4:52 AM
To: rcpp-devel at lists.r-forge.r-project.org
Subject: [Rcpp-devel] Getting the exact arithmetic as in R when Rcpp is used?
Hi,
The following shows the arithmetic in C++ is slightly different from
in R. Is there a way to get the exact arithmetic as in R?
~/dvcs_src/rexample/Rexample/cran/base/sum$ Rscript main_Rcpp.R
+ Rcpp::NumericVector vec(vx);
+ double sum = 0;
+ for (int i=0; i<vec.size(); i++) {
+ sum += vec[i];
+ }
+ return Rcpp::wrap(sum);
+ '
+ signature(vx='numeric')
+ , src
+ , plugin='Rcpp'
+ )
Attaching package: 'Rcpp'
The following object is masked from 'package:inline':
registerPlugin
vx=rep(.1, 10)
options(digits=22)
fun(vx)
[1] 0.9999999999999998889777