TMB Documentation  v1.9.11
gamma.hpp
1 #ifndef TINY_AD_GAMMA_H
2 #define TINY_AD_GAMMA_H
3 
4 #include "undefs.h" // Rcpp
5 /* Standalone ? */
6 #ifndef R_RCONFIG_H
7 #include <cmath>
8 #include <iostream>
9 #include <float.h> // INFINITY etc
10 #include <stdlib.h> // calloc (bessel)
11 #undef R_PosInf
12 #undef R_NegInf
13 #undef F77_NAME
14 #undef FALSE
15 #undef TRUE
16 #undef R_NaN
17 #undef R_FINITE
18 #define R_PosInf INFINITY
19 #define R_NegInf -INFINITY
20 #define F77_NAME(x) x
21 #define FALSE false
22 #define TRUE true
23 #define R_NaN NAN
24 #define R_FINITE(x) R_finite(x)
25 #endif
26 
27 namespace gamma_utils {
28 
29 /* Selected functions may be called ignoring derivatives */
30 template<class T> int R_finite(T x) { return std::isfinite(asDouble(x)); }
31 template<class T> int isnan(T x) { return std::isnan(asDouble(x)); }
32 
33 /* Common defines for Rmath routines */
34 #undef ML_ERROR
35 #undef MATHLIB_ERROR
36 #undef MATHLIB_WARNING
37 #undef MATHLIB_WARNING2
38 #undef MATHLIB_WARNING3
39 #undef MATHLIB_WARNING4
40 #undef MATHLIB_WARNING5
41 #undef ML_POSINF
42 #undef ML_NEGINF
43 #undef ML_NAN
44 #undef M_SQRT_2dPI
45 #undef ISNAN
46 # define ML_ERROR(x, s) /* nothing */
47 # define MATHLIB_ERROR(fmt,x) /* nothing */
48 # define MATHLIB_WARNING(fmt,x) /* nothing */
49 # define MATHLIB_WARNING2(fmt,x,x2) /* nothing */
50 # define MATHLIB_WARNING3(fmt,x,x2,x3) /* nothing */
51 # define MATHLIB_WARNING4(fmt,x,x2,x3,x4) /* nothing */
52 # define MATHLIB_WARNING5(fmt,x,x2,x3,x4,x5) /* nothing */
53 #define ML_POSINF R_PosInf
54 #define ML_NEGINF R_NegInf
55 #define ML_NAN R_NaN
56 #define M_SQRT_2dPI 0.797884560802865355879892119869 /* sqrt(2/pi) */
57 #define ISNAN(x) (isnan(x)!=0)
58 
59 // Re-defines
60 // #undef Rboolean
61 // #define Rboolean bool
62 
63 // Fake that Rmath.h is included - and take explicitly what we need
64 #ifndef RMATH_H
65 #define RMATH_H
66 #endif
67 #ifndef M_LOG10_2
68 #define M_LOG10_2 0.301029995663981195213738894724 /* log10(2) */
69 #endif
70 #ifndef M_LN_SQRT_PI
71 #define M_LN_SQRT_PI 0.572364942924700087071713675677 /* log(sqrt(pi))
72  == log(pi)/2 */
73 #endif
74 #ifndef M_LN_SQRT_2PI
75 #define M_LN_SQRT_2PI 0.918938533204672741780329736406 /* log(sqrt(2*pi))
76  == log(2*pi)/2 */
77 #endif
78 #ifndef M_SQRT_PI
79 #define M_SQRT_PI 1.772453850905516027298167483341 /* sqrt(pi) */
80 #endif
81 
82 #ifndef M_LN_SQRT_PId2
83 #define M_LN_SQRT_PId2 0.225791352644727432363097614947 /* log(sqrt(pi/2))
84  == log(pi/2)/2 */
85 #endif
86 
87 // Fake that nmath.h is included - and take explicitly what we need
88 #ifndef MATHLIB_PRIVATE_H
89 #define MATHLIB_PRIVATE_H
90 #endif
91 #ifdef HAVE_VISIBILITY_ATTRIBUTE
92 # define attribute_hidden __attribute__ ((visibility ("hidden")))
93 #else
94 # define attribute_hidden
95 #endif
96 #define ML_ERR_return_NAN { ML_ERROR(ME_DOMAIN, ""); return ML_NAN; }
97 
98 
99 // Forward declare for stirlerr:
100 template<class Float> Float lgammafn(Float x);
101 // For gamma.cpp:
102 template <class Float> Float sinpi(Float x) { return sin(x * M_PI); }
103 
104 #include "chebyshev.cpp"
105 #include "lgammacor.cpp"
106 #undef nalgm
107 #undef xbig
108 #undef xmax
109 #include "stirlerr.cpp"
110 #undef S0
111 #undef S1
112 #undef S2
113 #undef S3
114 #undef S4
115 #include "gamma.cpp"
116 #undef ngam
117 #undef xmin
118 #undef xmax
119 #undef xsml
120 #undef dxrel
121 #include "lgamma.cpp"
122 #undef xmax
123 #undef dxrel
124 #include "gamma_cody.cpp"
125 #include "undefs.h"
126 
127 } // End namespace gamma_utils
128 
129 // using gamma_utils::lgammafn;
130 // using gamma_utils::gammafn;
131 // using gamma_utils::Rf_gamma_cody;
132 
133 #endif
License: GPL v2