vSMC  v3.0.0
Scalable Monte Carlo
constants.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/math/constants.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2016, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_MATH_CONSTANTS_HPP
33 #define VSMC_MATH_CONSTANTS_HPP
34 
35 #define VSMC_DEFINE_MATH_CONSTANTS(name, val) \
36  template <typename T> \
37  inline constexpr T const_##name() noexcept \
38  { \
39  return static_cast<T>(val##l); \
40  } \
41  template <> \
42  inline constexpr float const_##name<float>() noexcept \
43  { \
44  return val##f; \
45  } \
46  template <> \
47  inline constexpr double const_##name<double>() noexcept \
48  { \
49  return val; \
50  } \
51  template <> \
52  inline constexpr long double const_##name<long double>() noexcept \
53  { \
54  return val##l; \
55  }
56 
57 namespace vsmc
58 {
59 
62 VSMC_DEFINE_MATH_CONSTANTS(pi, 3.141592653589793238462643383279502884197)
63 
64 VSMC_DEFINE_MATH_CONSTANTS(pi_2, 6.283185307179586476925286766559005768394)
67 
70 VSMC_DEFINE_MATH_CONSTANTS(pi_inv, 0.3183098861837906715377675267450287240689)
71 
74 VSMC_DEFINE_MATH_CONSTANTS(pi_sqr, 9.869604401089358618834490999876151135314)
75 
78 VSMC_DEFINE_MATH_CONSTANTS(pi_by2, 1.570796326794896619231321691639751442099)
79 
82 VSMC_DEFINE_MATH_CONSTANTS(pi_by3, 1.047197551196597746154214461093167628066)
83 
86 VSMC_DEFINE_MATH_CONSTANTS(pi_by4, 0.7853981633974483096156608458198757210493)
87 
90 VSMC_DEFINE_MATH_CONSTANTS(pi_by6, 0.5235987755982988730771072305465838140329)
91 
94 VSMC_DEFINE_MATH_CONSTANTS(pi_2by3, 2.094395102393195492308428922186335256131)
95 
98 VSMC_DEFINE_MATH_CONSTANTS(pi_3by4, 2.356194490192344928846982537459627163148)
99 
102 VSMC_DEFINE_MATH_CONSTANTS(pi_4by3, 4.188790204786390984616857844372670512263)
103 
106 VSMC_DEFINE_MATH_CONSTANTS(sqrt_pi, 1.772453850905516027298167483341145182798)
107 
111  sqrt_pi_2, 2.506628274631000502415765284811045253007)
112 
116  sqrt_pi_inv, 0.5641895835477562869480794515607725858441)
117 
121  sqrt_pi_by2, 1.253314137315500251207882642405522626503)
122 
126  sqrt_pi_by3, 1.023326707946488488479551624889264860707)
127 
131  sqrt_pi_by4, 0.8862269254527580136490837416705725913988)
132 
136  sqrt_pi_by6, 0.7236012545582676593630146272907957678721)
137 
141  sqrt_pi_2by3, 1.447202509116535318726029254581591535744)
142 
146  sqrt_pi_3by4, 1.534990061919732732719327437333897291061)
147 
151  sqrt_pi_4by3, 2.046653415892976976959103249778529721415)
152 
155 VSMC_DEFINE_MATH_CONSTANTS(ln_pi, 1.144729885849400174143427351353058711647)
156 
159 VSMC_DEFINE_MATH_CONSTANTS(ln_pi_2, 1.837877066409345483560659472811235279723)
160 
164  ln_pi_by2, 0.4515827052894548647261952298948821435718)
165 
169  ln_pi_by3, 0.04611759718129048274818211443053300699980)
170 
174  ln_pi_by4, -0.2415644752704904446910368915632944245037)
175 
179  ln_pi_by6, -0.6470295833786548266690500070276435610757)
180 
184  ln_pi_2by3, 0.7392647777412357921654142358887095750753)
185 
189  ln_pi_3by4, 0.8570478133976192467042083453592312801438)
190 
194  ln_pi_4by3, 1.432411958301181101582646357346886143151)
195 
198 VSMC_DEFINE_MATH_CONSTANTS(e, 2.718281828459045235360287471352662497757)
199 
202 VSMC_DEFINE_MATH_CONSTANTS(e_inv, 0.3678794411714423215955237701614608674458)
203 
206 VSMC_DEFINE_MATH_CONSTANTS(sqrt_e, 1.648721270700128146848650787814163571654)
207 
211  sqrt_e_inv, 0.6065306597126334236037995349911804534419)
212 
215 VSMC_DEFINE_MATH_CONSTANTS(sqrt_2, 1.414213562373095048801688724209698078570)
216 
219 VSMC_DEFINE_MATH_CONSTANTS(sqrt_3, 1.732050807568877293527446341505872366943)
220 
223 VSMC_DEFINE_MATH_CONSTANTS(sqrt_5, 2.236067977499789696409173668731276235441)
224 
227 VSMC_DEFINE_MATH_CONSTANTS(sqrt_10, 3.162277660168379331998893544432718533720)
228 
232  sqrt_1by2, 0.7071067811865475244008443621048490392848)
233 
237  sqrt_1by3, 0.5773502691896257645091487805019574556476)
238 
242  sqrt_1by5, 0.4472135954999579392818347337462552470881)
243 
247  sqrt_1by10, 0.3162277660168379331998893544432718533720)
248 
251 VSMC_DEFINE_MATH_CONSTANTS(ln_2, 0.6931471805599453094172321214581765680755)
252 
255 VSMC_DEFINE_MATH_CONSTANTS(ln_3, 1.098612288668109691395245236922525704647)
256 
259 VSMC_DEFINE_MATH_CONSTANTS(ln_5, 1.609437912434100374600759333226187639526)
260 
263 VSMC_DEFINE_MATH_CONSTANTS(ln_10, 2.302585092994045684017991454684364207601)
264 
267 VSMC_DEFINE_MATH_CONSTANTS(ln_inv_2, 1.442695040888963407359924681001892137427)
268 
272  ln_inv_3, 0.9102392266268373936142401657361070006126)
273 
277  ln_inv_5, 0.6213349345596118107071993881805725841234)
278 
282  ln_inv_10, 0.4342944819032518276511289189166050822944)
283 
287  ln_ln_2, -0.3665129205816643270124391582326694694543)
288 
289 } // namespace vsmc
290 
291 #endif // VSMC_MATH_CONSTANTS_HPP
Definition: monitor.hpp:48
#define VSMC_DEFINE_MATH_CONSTANTS(name, val)
Definition: constants.hpp:35