1 #ifndef TINY_AD_BESSEL_H 2 #define TINY_AD_BESSEL_H 18 #define R_PosInf INFINITY 19 #define R_NegInf -INFINITY 24 #define R_FINITE(x) R_finite(x) 27 #include "../gamma/gamma.hpp" 30 using gamma_utils::Rf_gamma_cody;
33 template<
class T>
int R_finite(T x) {
return std::isfinite(asDouble(x)); }
34 template<
class T>
int isnan(T x) {
return std::isnan(asDouble(x)); }
39 #undef MATHLIB_WARNING 40 #undef MATHLIB_WARNING2 41 #undef MATHLIB_WARNING3 42 #undef MATHLIB_WARNING4 43 #undef MATHLIB_WARNING5 49 # define ML_ERROR(x, s) 50 # define MATHLIB_ERROR(fmt,x) 51 # define MATHLIB_WARNING(fmt,x) 52 # define MATHLIB_WARNING2(fmt,x,x2) 53 # define MATHLIB_WARNING3(fmt,x,x2,x3) 54 # define MATHLIB_WARNING4(fmt,x,x2,x3,x4) 55 # define MATHLIB_WARNING5(fmt,x,x2,x3,x4,x5) 56 #define ML_POSINF R_PosInf 57 #define ML_NEGINF R_NegInf 59 #define M_SQRT_2dPI 0.797884560802865355879892119869 60 #define ISNAN(x) (isnan(x)!=0) 63 #define MATHLIB_STANDALONE 1 64 #include "bessel_k.cpp" 68 template <
class Float> Float sinpi(Float x) {
return sin(x * M_PI); }
69 template <
class Float> Float cospi(Float x) {
return cos(x * M_PI); }
70 template<
class S,
class T>
71 T fmax2(S x, T y) {
return (x < y) ? y : x;}
72 template<
class Float> Float bessel_y(Float x, Float alpha);
73 #include "bessel_j.cpp" 74 #include "bessel_y.cpp" 78 Float R_pow(Float x, Float n) {
return pow(x, n);}
80 Float R_pow_di(Float x,
int n)
84 if (ISNAN(x))
return x;
86 if (!R_FINITE(x))
return R_pow(x, (Float)n);
87 if (n < 0) { n = -n; x = 1/x; }
90 if(n >>= 1) x *= x;
else break;
96 Float ldexp (Float x,
int expo) {
97 return exp( log(x) + expo * log(2.0) );
100 #include "bessel_i.cpp" 101 #undef MATHLIB_STANDALONE