与R_PosInf
进行比较是否可靠,以便适用于任何double
number
number < R_PosInf == true
答案 0 :(得分:3)
很容易尝试!
#include <Rcpp.h>
// [[Rcpp::export]]
bool compToInf(double x) {
return x < R_PosInf;
}
/*** R
compToInf(.Machine$double.xmax) ## largest representable double
compToInf(Inf)
*/
R> sourceCpp("/tmp/so50229770.cpp")
R> compToInf(.Machine$double.xmax) ## largest representable double
[1] TRUE
R> compToInf(Inf)
[1] FALSE
R>