constants.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_CONSTANTS_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_CONSTANTS_HPP
3 
4 #include <boost/math/constants/constants.hpp>
5 #include <limits>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * The base of the natural logarithm,
12  * \f$ e \f$.
13  */
14 const double E = boost::math::constants::e<double>();
15 
16 /**
17  * The value of the square root of 2,
18  * \f$ \sqrt{2} \f$.
19  */
20 const double SQRT_2 = std::sqrt(2.0);
21 
22 /**
23  * The value of 1 over the square root of 2,
24  * \f$ 1 / \sqrt{2} \f$.
25  */
26 const double INV_SQRT_2 = 1.0 / SQRT_2;
27 
28 /**
29  * The natural logarithm of 2,
30  * \f$ \log 2 \f$.
31  */
32 const double LOG_2 = std::log(2.0);
33 
34 /**
35  * The natural logarithm of 10,
36  * \f$ \log 10 \f$.
37  */
38 const double LOG_10 = std::log(10.0);
39 
40 /**
41  * Positive infinity.
42  */
43 const double INFTY = std::numeric_limits<double>::infinity();
44 
45 /**
46  * Negative infinity.
47  */
48 const double NEGATIVE_INFTY = -std::numeric_limits<double>::infinity();
49 
50 /**
51  * (Quiet) not-a-number value.
52  */
53 const double NOT_A_NUMBER = std::numeric_limits<double>::quiet_NaN();
54 
55 /**
56  * Smallest positive value.
57  */
59 
60 /**
61  * Largest negative value (i.e., smallest absolute value).
62  */
64 
65 /**
66  * Largest rate parameter allowed in Poisson RNG
67  */
68 const double POISSON_MAX_RATE = std::pow(2.0, 30);
69 
70 /**
71  * Log pi divided by 4
72  * \f$ \log \pi / 4 \f$
73  */
74 const double LOG_PI_OVER_FOUR
75  = std::log(boost::math::constants::pi<double>()) / 4.0;
76 
77 /**
78  * Return the value of pi.
79  *
80  * @return Pi.
81  */
82 inline double pi() { return boost::math::constants::pi<double>(); }
83 
84 /**
85  * Return the base of the natural logarithm.
86  *
87  * @return Base of natural logarithm.
88  */
89 inline double e() { return E; }
90 
91 /**
92  * Return the square root of two.
93  *
94  * @return Square root of two.
95  */
96 inline double sqrt2() { return SQRT_2; }
97 
98 /**
99  * Return natural logarithm of ten.
100  *
101  * @return Natural logarithm of ten.
102  */
103 inline double log10() { return LOG_10; }
104 
105 /**
106  * Return positive infinity.
107  *
108  * @return Positive infinity.
109  */
110 inline double positive_infinity() { return INFTY; }
111 
112 /**
113  * Return negative infinity.
114  *
115  * @return Negative infinity.
116  */
117 inline double negative_infinity() { return NEGATIVE_INFTY; }
118 
119 /**
120  * Return (quiet) not-a-number.
121  *
122  * @return Quiet not-a-number.
123  */
124 inline double not_a_number() { return NOT_A_NUMBER; }
125 
126 /**
127  * Returns the difference between 1.0 and the next value
128  * representable.
129  *
130  * @return Minimum positive number.
131  */
132 inline double machine_precision() { return EPSILON; }
133 
134 const double SQRT_PI = std::sqrt(boost::math::constants::pi<double>());
135 
136 const double SQRT_2_TIMES_SQRT_PI = SQRT_2 * SQRT_PI;
137 
138 const double TWO_OVER_SQRT_PI = 2.0 / SQRT_PI;
139 
141 
142 const double INV_SQRT_TWO_PI
143  = 1.0 / std::sqrt(2.0 * boost::math::constants::pi<double>());
144 
145 const double LOG_PI = std::log(boost::math::constants::pi<double>());
146 
147 const double LOG_SQRT_PI = std::log(SQRT_PI);
148 
149 const double LOG_ZERO = std::log(0.0);
150 
151 const double LOG_TWO = std::log(2.0);
152 
153 const double LOG_HALF = std::log(0.5);
154 
155 const double NEG_LOG_TWO = -LOG_TWO;
156 
157 const double NEG_LOG_SQRT_TWO_PI
158  = -std::log(std::sqrt(2.0 * boost::math::constants::pi<double>()));
159 
160 const double NEG_LOG_PI = -LOG_PI;
161 
162 const double NEG_LOG_SQRT_PI
163  = -std::log(std::sqrt(boost::math::constants::pi<double>()));
164 
165 const double NEG_LOG_TWO_OVER_TWO = -LOG_TWO / 2.0;
166 
167 const double LOG_TWO_PI = LOG_TWO + LOG_PI;
168 
169 const double NEG_LOG_TWO_PI = -LOG_TWO_PI;
170 
171 } // namespace math
172 } // namespace stan
173 
174 #endif
const double LOG_2
Definition: constants.hpp:32
const double NEG_LOG_PI
Definition: constants.hpp:160
const double LOG_HALF
Definition: constants.hpp:153
const double INV_SQRT_TWO_PI
Definition: constants.hpp:143
const double NOT_A_NUMBER
Definition: constants.hpp:53
const double LOG_PI
Definition: constants.hpp:145
T sqrt(T number)
Definition: d0nt_math.hpp:156
constexpr T pow(T x)
Definition: pow.h:75
const double NEG_LOG_SQRT_PI
Definition: constants.hpp:163
const double LOG_SQRT_PI
Definition: constants.hpp:147
const double LOG_10
Definition: constants.hpp:38
fvar< T > log10(const fvar< T > &x)
Definition: log10.hpp:11
const double LOG_ZERO
Definition: constants.hpp:149
const double LOG_TWO
Definition: constants.hpp:151
const double LOG_TWO_PI
Definition: constants.hpp:167
double sqrt2()
Definition: constants.hpp:96
const double TWO_OVER_SQRT_PI
Definition: constants.hpp:138
const double SQRT_2_TIMES_SQRT_PI
Definition: constants.hpp:136
const double SQRT_2
Definition: constants.hpp:20
const double INV_SQRT_2
Definition: constants.hpp:26
const double EPSILON
Definition: constants.hpp:58
const double LOG_PI_OVER_FOUR
Definition: constants.hpp:75
double machine_precision()
Definition: constants.hpp:132
const double NEG_TWO_OVER_SQRT_PI
Definition: constants.hpp:140
const double POISSON_MAX_RATE
Definition: constants.hpp:68
const double NEG_LOG_SQRT_TWO_PI
Definition: constants.hpp:158
double positive_infinity()
Definition: constants.hpp:110
double e()
Definition: constants.hpp:89
const double E
Definition: constants.hpp:14
const double NEG_LOG_TWO
Definition: constants.hpp:155
double epsilon
const double NEG_LOG_TWO_PI
Definition: constants.hpp:169
const double NEG_LOG_TWO_OVER_TWO
Definition: constants.hpp:165
const double INFTY
Definition: constants.hpp:43
double pi()
Definition: constants.hpp:82
double not_a_number()
Definition: constants.hpp:124
const double NEGATIVE_INFTY
Definition: constants.hpp:48
const double NEGATIVE_EPSILON
Definition: constants.hpp:63
const double SQRT_PI
Definition: constants.hpp:134
double negative_infinity()
Definition: constants.hpp:117