Phi
constants.hpp
1 #ifndef INCG_PHI_CORE_MATH_CONSTANTS_HPP
2 #define INCG_PHI_CORE_MATH_CONSTANTS_HPP
3 
4 #include "phi/phi_config.hpp"
5 
6 #if PHI_HAS_EXTENSION_PRAGMA_ONCE()
7 # pragma once
8 #endif
9 
10 #include "phi/compiler_support/constexpr.hpp"
11 #include "phi/compiler_support/inline.hpp"
12 #include "phi/compiler_support/nodiscard.hpp"
13 #include "phi/compiler_support/noexcept.hpp"
14 #include "phi/core/types.hpp"
15 #include "phi/core/unsafe_cast.hpp"
16 #include "phi/preprocessor/glue.hpp"
17 
18 #define DETAIL_PHI_DECLARE_CONSTANT(name, value) \
19  template <typename TypeT> \
20  PHI_NODISCARD PHI_ALWAYS_INLINE PHI_CONSTEXPR TypeT PHI_GLUE(name, _v)() PHI_NOEXCEPT \
21  { \
22  return ::phi::unsafe_cast<TypeT>(value); \
23  } \
24  \
25  PHI_NODISCARD PHI_ALWAYS_INLINE PHI_CONSTEXPR ::phi::f64 name() PHI_NOEXCEPT \
26  { \
27  return ::phi::PHI_GLUE(name, _v)<f64>(); \
28  } \
29  PHI_NODISCARD PHI_ALWAYS_INLINE PHI_CONSTEXPR ::phi::f64 PHI_GLUE(name, _64)() PHI_NOEXCEPT \
30  { \
31  return ::phi::PHI_GLUE(name, _v)<f64>(); \
32  } \
33  PHI_NODISCARD PHI_ALWAYS_INLINE PHI_CONSTEXPR ::phi::f32 PHI_GLUE(name, _32)() PHI_NOEXCEPT \
34  { \
35  return ::phi::PHI_GLUE(name, _v)<f32>(); \
36  }
37 
38 DETAIL_PHI_BEGIN_NAMESPACE()
39 
40 // Euler's number (\a e)
41 DETAIL_PHI_DECLARE_CONSTANT(
42  e,
43  2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746L)
44 
45 // Pi (π)
46 DETAIL_PHI_DECLARE_CONSTANT(
47  pi,
48  3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651L)
49 
50 // 2 * π
51 DETAIL_PHI_DECLARE_CONSTANT(
52  two_pi,
53  6.28318530717958647692528676655900576839433879875021164194988918461563281257241799725606965068423413596429617303L)
54 
55 // Square root of π
56 DETAIL_PHI_DECLARE_CONSTANT(
57  sqrt_pi,
58  1.77245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362L)
59 
60 // π / 2
61 DETAIL_PHI_DECLARE_CONSTANT(
62  half_pi,
63  1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404326L)
64 
65 // 3 / 2π
66 DETAIL_PHI_DECLARE_CONSTANT(three_over_two_pi, 4.71238898038468985769396507491925432L)
67 
68 // π / 4
69 DETAIL_PHI_DECLARE_CONSTANT(quarter_pi, 0.785398163397448309615660845819875721L)
70 
71 // 1 / π
72 DETAIL_PHI_DECLARE_CONSTANT(one_over_pi, 0.318309886183790671537767526745028724L)
73 
74 // 1 / 2π
75 DETAIL_PHI_DECLARE_CONSTANT(one_over_two_pi, 0.159154943091895335768883763372514362L)
76 
77 // 2 / π
78 DETAIL_PHI_DECLARE_CONSTANT(two_over_pi, 0.636619772367581343075535053490057448L)
79 
80 // 4 / π
81 DETAIL_PHI_DECLARE_CONSTANT(four_over_pi, 1.273239544735162686151070106980114898L)
82 
83 // 2 / sqrt(π)
84 DETAIL_PHI_DECLARE_CONSTANT(two_over_sqrt_pi, 1.12837916709551257389615890312154517L)
85 
86 // 1 / sqrt(2)
87 DETAIL_PHI_DECLARE_CONSTANT(one_over_sqrt_two, 0.707106781186547524400844362104849039L)
88 
89 // sqrt(π / 2)
90 DETAIL_PHI_DECLARE_CONSTANT(
91  sqrt_half_pi,
92  1.25331413731550025120788264240552262650349337030496915831496178817114682730392098747329791918902863305800498633L)
93 
94 // sqrt(2π)
95 DETAIL_PHI_DECLARE_CONSTANT(
96  sqrt_two_pi,
97  2.50662827463100050241576528481104525300698674060993831662992357634229365460784197494659583837805726611600997267L)
98 
99 // sqrt(2)
100 DETAIL_PHI_DECLARE_CONSTANT(
101  sqrt_two,
102  1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157L)
103 
104 // sqrt(3)
105 DETAIL_PHI_DECLARE_CONSTANT(
106  sqrt_three,
107  1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756756261414154L)
108 
109 DETAIL_PHI_DECLARE_CONSTANT(
110  deg2rad,
111  0.017453292519943295769236907684886127134428718885417254560971914401710091146034494436822415696345095L)
112 
113 DETAIL_PHI_DECLARE_CONSTANT(
114  rad2deg,
115  57.295779513082320876798154814105170332405472466564321549160243861202847148321552632440968995851111L)
116 
117 // golden ratio (phi)
118 DETAIL_PHI_DECLARE_CONSTANT(golden_ratio,
119  1.6180339887498948482045868343656381177203091798057628621L)
120 
121 // cos(1) / 2
122 DETAIL_PHI_DECLARE_CONSTANT(cos_one_over_two, 0.877582561890372716130286068203503191L)
123 
124 DETAIL_PHI_END_NAMESPACE()
125 
126 #undef DETAIL_PHI_DECLARE_CONSTANT
127 
128 #endif // INCG_PHI_CORE_MATH_CONSTANTS_HPP
Definition: is_nothrow_constructible.test.cpp:149