Clawish
Clawish

Reputation: 2964

Can I compare with R_PosInf

Is it reliable to compare with R_PosInf so that for any double number

number < R_PosInf == true

Upvotes: 1

Views: 216

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368389

Easy enough to try!

Code

#include <Rcpp.h>

// [[Rcpp::export]]
bool compToInf(double x) {
  return x < R_PosInf;
}

/*** R
compToInf(.Machine$double.xmax)   ## largest representable double
compToInf(Inf)
*/

Demo

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

R> compToInf(.Machine$double.xmax)   ## largest representable double
[1] TRUE

R> compToInf(Inf)
[1] FALSE
R> 

Upvotes: 5

Related Questions