[Rcpp-commits] r3174 - in pkg/Rcpp: . inst inst/doc/Rcpp-FAQ
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 17 15:37:14 CEST 2011
Author: edd
Date: 2011-08-17 15:37:14 +0200 (Wed, 17 Aug 2011)
New Revision: 3174
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/NEWS
pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw
Log:
added example kindly supplied by Murray of how 64 bit integer types are converted with precision loss
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2011-08-17 13:36:35 UTC (rev 3173)
+++ pkg/Rcpp/ChangeLog 2011-08-17 13:37:14 UTC (rev 3174)
@@ -1,3 +1,9 @@
+2011-08-17 Dirk Eddelbuettel <edd at debian.org>
+
+ * inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Added a short section including an
+ example on the issue raised by Murray wherein 64 bit 'long' integer
+ types can be cast with loss to numeric types without error or warning.
+
2011-07-28 Dirk Eddelbuettel <edd at debian.org>
* inst/unitTests/runit.Function.R: new unit test for accessing a
Modified: pkg/Rcpp/inst/NEWS
===================================================================
--- pkg/Rcpp/inst/NEWS 2011-08-17 13:36:35 UTC (rev 3173)
+++ pkg/Rcpp/inst/NEWS 2011-08-17 13:37:14 UTC (rev 3174)
@@ -1,5 +1,8 @@
0.9.7 2011-xx-yy
+ o New Rcpp-FAQ example warning of lossy conversion from 64-bit long
+ integer types into a 53-bit mantissa which has no clear fix yet.
+
o New unit test for accessing a non-exported function from a namespace
0.9.6 2011-07-26
Modified: pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw 2011-08-17 13:36:35 UTC (rev 3173)
+++ pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw 2011-08-17 13:37:14 UTC (rev 3174)
@@ -400,7 +400,10 @@
operations. That is a mouthful of words meaning that it makes the code go
faster by using fiendishly clever ways available via the so-called template
meta programming, an advanced \proglang{C++} technique.
+Also, the \pkg{RcppEigen} package provides an alternative using the
+\href{Eigen}{http://eigen.tuxfamily.org} template library.
+
The following example is adapted from the examples available at the project
page of Armadillo. It calculates $ x' \times Y^{-1} \times z$
@@ -514,7 +517,11 @@
% A %*% B
% @
+Armadillo supports a full range of common linear algebra operations.
+The \pkg{RcppEigen} package provides an alternative using the
+\href{Eigen}{http://eigen.tuxfamily.org} template library.
+
\subsection{How do I write a plugin for \pkg{inline} ?}
\begin{quote}
@@ -576,6 +583,41 @@
@
%
+\subsection{Why can long long types not be cast correctly?}
+
+That is a good and open question. We rely on the basic \proglang{R} types,
+notably \code{integer} and \code{numeric}. These can be cast to and from
+\proglang{C++} types without problems. But there are corner cases. The
+following example, contributed by a user, shows that we cannot reliably cast
+\code{long} types (on a 64-bit machines).
+
+<<eval=FALSE>>=
+BigInts <- cxxfunction(signature(),
+ 'std::vector<long> bigints;
+ bigints.push_back(12345678901234567LL);
+ bigints.push_back(12345678901234568LL);
+ Rprintf("Difference of %ld\\n", 12345678901234568LL - 12345678901234567LL);
+ return wrap(bigints);', plugin="Rcpp", includes="#include <vector>")
+
+retval<-BigInts()
+
+# Unique 64-bit integers were cast to identical lower precision numerics
+# behind my back with no warnings or errors whatsoever. Error.
+
+stopifnot(length(unique(retval)) == 2)
+@
+%
+
+While the difference of one is evident at the \proglang{C++} level, it is no
+longer present once cast to \proglang{R}. The 64-bit integer values get cast
+to a floating point types with a 53-bit mantissa. We do not have a good
+suggestion or fix for casting 64-bit integer values: 32-bit integer values
+fit into \code{integer} types, up to 53 bit precision fits into
+\code{numeric} and beyond that truly large integers may have to converted
+(rather crudely) to text and re-parsed. Using a different representation as
+for example from the \href{http://gmplib.org/}{GNU Multiple Precision Arithmetic
+ Library} may be an alternative.
+
\section{Support}
\subsection{Is the API documented ?}
More information about the Rcpp-commits
mailing list