I'm not sure what compliers you are using out there, but gcc does have a way to enable warnings for this type of implicit conversion.
-Wconversion Warn for implicit conversions that may alter a value. This includes conversions between real and integer... http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html Please check this, as it's not entirely obvious from the description that it will pick up a warning in this case. Thanks, Dale Smith, Ph.D. Senior Financial Quantitative Analyst Risk & Compliance Fiserv. 107 Technology Park Norcross, GA 30092 Office: 678-375-5315 Mail: dale.sm...@fiserv.com www.fiserv.com -----Original Message----- From: rcpp-devel-boun...@r-forge.wu-wien.ac.at [mailto:rcpp-devel-boun...@r-forge.wu-wien.ac.at] On Behalf Of Romain Francois Sent: Thursday, November 15, 2012 9:18 AM To: Hadley Wickham Cc: rcpp-devel Subject: Re: [Rcpp-devel] Loops, iterators and accumulate Le 15/11/12 15:14, Hadley Wickham a écrit : > On Thu, Nov 15, 2012 at 8:11 AM, Romain Francois > <rom...@r-enthusiasts.com> wrote: >> I'm not getting the same results, so I might not make the same conclusions: >> >> >> Unit: microseconds >> expr min lq median uq max >> 1 sum(x) 16.072 16.161 16.2090 16.3110 21.721 >> 2 sum1(x) 10.771 10.954 11.0445 11.1910 16.163 >> 3 sum2(x) 48.438 48.567 48.6650 48.8425 61.116 >> 4 sum2a(x) 10.806 10.965 11.0695 11.2080 17.401 >> 5 sum3(x) 10.835 10.967 11.0490 11.1875 23.943 >> 6 sum4(x) 10.847 10.989 11.0690 11.2160 16.331 >> >> For me that makes more sense. > > I just discovered the problem with my accumulate. I was doing: > > double total = std::accumulate(x.begin(), x.end(), 0); > > instead of > > double total = std::accumulate(x.begin(), x.end(), 0.0); > > Hadley Ah. Interesting. That makes sense, lots of conversion from double to int to accumulate into an int. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 R Graph Gallery: http://gallery.r-enthusiasts.com `- http://bit.ly/SweN1Z : SuperStorm Sandy blog: http://romainfrancois.blog.free.fr |- http://bit.ly/RE6sYH : OOP with Rcpp modules `- http://bit.ly/Thw7IK : Rcpp modules more flexible _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel