TMB Documentation  v1.9.11
pbeta.hpp
1 #ifndef TINY_AD_BETA_H
2 #define TINY_AD_BETA_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 toms708 {
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 // Fake that Rmath.h is included - and take explicitly what we need
60 #ifndef RMATH_H
61 #define RMATH_H
62 #endif
63 #ifndef M_LOG10_2
64 #define M_LOG10_2 0.301029995663981195213738894724 /* log10(2) */
65 #endif
66 #ifndef M_LN_SQRT_PI
67 #define M_LN_SQRT_PI 0.572364942924700087071713675677 /* log(sqrt(pi))
68  == log(pi)/2 */
69 #endif
70 #ifndef M_LN_SQRT_2PI
71 #define M_LN_SQRT_2PI 0.918938533204672741780329736406 /* log(sqrt(2*pi))
72  == log(2*pi)/2 */
73 #endif
74 #ifndef M_SQRT_PI
75 #define M_SQRT_PI 1.772453850905516027298167483341 /* sqrt(pi) */
76 #endif
77 
78 // logspace_add
79 template<class T>
80 T fmax2(T x, T y) {return (x < y) ? y : x;}
81 template<class T>
82 T logspace_add (const T &logx, const T &logy) {
83  return fmax2 (logx, logy) + log1p (exp (-fabs (logx - logy)));
84 }
85 
86 // Fake that nmath.h is included - and take explicitly what we need
87 #ifndef MATHLIB_PRIVATE_H
88 #define MATHLIB_PRIVATE_H
89 #endif
90 #ifdef HAVE_VISIBILITY_ATTRIBUTE
91 # define attribute_hidden __attribute__ ((visibility ("hidden")))
92 #else
93 # define attribute_hidden
94 #endif
95 #define ML_ERR_return_NAN { ML_ERROR(ME_DOMAIN, ""); return ML_NAN; }
96 
97 #include "d1mach.cpp"
98 #include "i1mach.cpp"
99 #include "toms708.cpp"
100 #include "pbeta.cpp"
101 
102 // Cleanup macros (see toms708.cpp)
103 #undef min
104 #undef max
105 #include "undefs.h"
106 
107 } // End namespace toms708
108 
109 // using toms708::pbeta;
110 
111 #endif
Type logspace_add(Type logx, Type logy)
Addition in log-space.
License: GPL v2