【发布时间】:2013-12-24 21:26:08
【问题描述】:
我正在尝试从 Rcpp 函数的双精度输出中打印更多数字,但无法弄清楚如何...我查看了 How do I print a double value with full precision using cout? 和其他地方的通用 C++ 答案,但是我在Rcpp 中看不到如何操作,除非使用printf,我认为这是最后的手段...
require(inline)
code <- '
double x=1.0;
std::cout.precision(10); // compiles but does nothing
Rcpp::Rcout.precision(10); // compiles but does nothing
printf("(1) %1.10lf\\n",x); // works but bad practice
Rcpp::Rcout << "(2) " << x << std::endl;
Rcpp::Rcout << "(3) " << std::setprecision(10) << x << std::endl;
return Rcpp::wrap(0);
'
fun <- rcpp(sig=c(v=0),body=code,includes="#include <iomanip>")
fun(1)
## (1) 1.0000000000
## (2) 1
## (3) 1
## [1] 0
【问题讨论】:
-
在我维护的两个 Rcpp 实现中将此添加为问题:github.com/romainfrancois/Rcpp11/issues/67github.com/romainfrancois/Rcpp98/issues/10