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  */
58 const double EPSILON = std::numeric_limits<double>::epsilon();
59 
60 /**
61  * Largest negative value (i.e., smallest absolute value).
62  */
63 const double NEGATIVE_EPSILON = -std::numeric_limits<double>::epsilon();
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  */
pi()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  */
e()89 inline double e() { return E; }
90 
91 /**
92  * Return the square root of two.
93  *
94  * @return Square root of two.
95  */
sqrt2()96 inline double sqrt2() { return SQRT_2; }
97 
98 /**
99  * Return natural logarithm of ten.
100  *
101  * @return Natural logarithm of ten.
102  */
log10()103 inline double log10() { return LOG_10; }
104 
105 /**
106  * Return positive infinity.
107  *
108  * @return Positive infinity.
109  */
positive_infinity()110 inline double positive_infinity() { return INFTY; }
111 
112 /**
113  * Return negative infinity.
114  *
115  * @return Negative infinity.
116  */
negative_infinity()117 inline double negative_infinity() { return NEGATIVE_INFTY; }
118 
119 /**
120  * Return (quiet) not-a-number.
121  *
122  * @return Quiet not-a-number.
123  */
not_a_number()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  */
machine_precision()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 
140 const double NEG_TWO_OVER_SQRT_PI = -TWO_OVER_SQRT_PI;
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 const double LOG_EPSILON = std::log(EPSILON);
172 }  // namespace math
173 }  // namespace stan
174 
175 #endif
176