Robin,

Here is a quick example for using the BH package from CRAN to get rational 
numbers:

R> sourceCpp("/tmp/ratEx.cpp")

R> invisible(quicktest())
Half is 1/2
Sum of two halves is 1/1
R> 


where the code in /tmp/ratEx.cpp follows below.  I enable C++11 merely for
convenience as R (and g++) otherwise complain about 'long long'. Should your
compile not like or support C++11, just remove the line with the cpp11 plugin.

Dirk


#include <Rcpp.h>

// [[Rcpp::depends(BH)]]

#include <boost/rational.hpp>

// not needed but suppress 'long long' warnings from Boost
// [[Rcpp::plugins(cpp11)]]

// [[Rcpp::export]]
bool quicktest() {

  boost::rational<int> half(1,2);

  Rcpp::Rcout << "Half is " << half << std::endl;
  Rcpp::Rcout << "Sum of two halves is " << half + half << std::endl;

  return true;
}


/*** R
invisible(quicktest())
*/

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | [email protected]
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to