On 12 December 2014 at 10:09, Devin wrote: | ... but you can't set a mathematical operation equal to a string. I also tried: | | int test() | { | gsl_set_error_handler_off(); | if(gsl_sf_hyperg_2F1(1,1,1.1467003,1) == NAN){ | std::cout << "Error" << std::endl; | } | return 0; | } | | ... but the if-branch gets ignored. How can I achieve that the program runs through the if-branch?
Use a proper test for NaN. See eg http://gallery.rcpp.org/articles/working-with-missing-values/ or other documentation as eg the Writing R Extensions manual, my Rcpp book -- or the content of the Rcpp package. A simple way, using a macro from the R headers, is R> cppFunction('bool isItNan(double foo) { return ISNAN(foo); }') R> isItNan(NaN) [1] TRUE R> isItNan(3.14) [1] FALSE R> isItNan(3L) [1] FALSE R> There are (better) alternatives in the Rcpp sources, but some of the behaviour is subtle. Kevin once wrote a great answer at StackOverflow: http://stackoverflow.com/questions/26241085/rcpp-function-check-if-missing-value/26262984#26262984 Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel