Implementation of nextafter functionality in R

前端 未结 2 919
半阙折子戏
半阙折子戏 2020-12-19 13:09

Is there any implementation of functionality in R, such that it is possible to get the next representable floating point number from a given floating point number. This woul

2条回答
  •  孤城傲影
    2020-12-19 13:27

    If you prefer Rcpp:

    #include 
    using namespace Rcpp;
    
    // [[Rcpp::export]]
    double nextAfter(double x, double y) {
       return nextafter(x, y);
    }
    

    Then in R:

    sprintf("%.20f", 1)
    #[1] "1.00000000000000000000"
    sprintf("%.20f", nextAfter(1, 2))
    #[1] "1.00000000000000022204"
    

提交回复
热议问题