我可以和 R_PosInf 比较吗

Can I compare with R_PosInf

R_PosInf比较是否可靠,因此对于任何doublenumber

number < R_PosInf == true

很容易尝试!

代码

#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>