Antkeeper  0.0.1
numbers.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_MATH_NUMBERS_HPP
21 #define ANTKEEPER_MATH_NUMBERS_HPP
22 
23 #include <limits>
24 #include <numbers>
25 
26 namespace math {
27 
29 namespace numbers {
30 
32 template <class T>
33 inline constexpr T inf = std::numeric_limits<T>::infinity();
34 
36 template <class T>
37 inline constexpr T e = std::numbers::e_v<T>;
38 
40 template <class T>
41 inline constexpr T log2_e = std::numbers::log2e_v<T>;
42 
44 template <class T>
45 inline constexpr T log10_e = std::numbers::log10e_v<T>;
46 
48 template <class T>
49 inline constexpr T pi = std::numbers::pi_v<T>;
50 
52 template <class T>
53 inline constexpr T two_pi = pi<T> * T{2};
54 
56 template <class T>
57 inline constexpr T four_pi = pi<T> * T{4};
58 
60 template <class T>
61 inline constexpr T half_pi = pi<T> / T{2};
62 
64 template <class T>
65 inline constexpr T inv_pi = std::numbers::inv_pi_v<T>;
66 
68 template <class T>
69 inline constexpr T inv_sqrt_pi = std::numbers::inv_sqrtpi_v<T>;
70 
72 template <class T>
73 inline constexpr T sqr_pi = std::numbers::pi_v<T> * std::numbers::pi_v<T>;
74 
76 template <class T>
77 inline constexpr T ln_2 = std::numbers::ln2_v<T>;
78 
80 template <class T>
81 inline constexpr T ln_10 = std::numbers::ln10_v<T>;
82 
84 template <class T>
85 inline constexpr T sqrt_half = T{0.70710678118654752440084436210485};
86 
88 template <class T>
89 inline constexpr T sqrt_2 = std::numbers::sqrt2_v<T>;
90 
92 template <class T>
93 inline constexpr T sqrt_3 = std::numbers::sqrt3_v<T>;
94 
96 template <class T>
97 inline constexpr T inv_sqrt_3 = std::numbers::inv_sqrt3_v<T>;
98 
100 template <class T>
101 inline constexpr T sqrt_5 = T{2.2360679774997896964091736687313};
102 
104 template <class T>
105 inline constexpr T egamma = std::numbers::egamma_v<T>;
106 
108 template <class T>
109 inline constexpr T phi = std::numbers::phi_v<T>;
110 
112 template <class T>
113 inline constexpr T deg2rad = pi<T> / T{180};
114 
116 template <class T>
117 inline constexpr T rad2deg = T{180} / pi<T>;
118 
119 } // namespace numbers
120 
121 // Bring math::numbers into math namespace
122 using namespace numbers;
123 
124 } // namespace math
125 
126 #endif // ANTKEEPER_MATH_NUMBERS_HPP
constexpr T ln_10
ln(10).
Definition: numbers.hpp:81
constexpr T sqrt_2
sqrt(2)
Definition: numbers.hpp:89
constexpr T egamma
Euler–Mascheroni constant.
Definition: numbers.hpp:105
constexpr T sqrt_half
sqrt(0.5)
Definition: numbers.hpp:85
constexpr T e
e.
Definition: numbers.hpp:37
constexpr T inv_pi
1 / Pi.
Definition: numbers.hpp:65
constexpr T inv_sqrt_pi
1 / sqrt(Pi).
Definition: numbers.hpp:69
constexpr T inf
Positive infinity.
Definition: numbers.hpp:33
constexpr T phi
Golden ratio constant.
Definition: numbers.hpp:109
constexpr T log10_e
log10(e).
Definition: numbers.hpp:45
constexpr T pi
Pi.
Definition: numbers.hpp:49
constexpr T rad2deg
Radians-to-degrees conversion factor.
Definition: numbers.hpp:117
constexpr T inv_sqrt_3
1 / sqrt(3)
Definition: numbers.hpp:97
constexpr T four_pi
Pi * 4.
Definition: numbers.hpp:57
constexpr T ln_2
ln(2).
Definition: numbers.hpp:77
constexpr T half_pi
Pi / 2.
Definition: numbers.hpp:61
constexpr T log2_e
log2(e).
Definition: numbers.hpp:41
constexpr T two_pi
Pi * 2.
Definition: numbers.hpp:53
constexpr T sqrt_5
sqrt(5)
Definition: numbers.hpp:101
constexpr T deg2rad
Degrees-to-radians conversion factor.
Definition: numbers.hpp:113
constexpr T sqr_pi
Pi^2.
Definition: numbers.hpp:73
constexpr T sqrt_3
sqrt(3)
Definition: numbers.hpp:93
Mathematical functions and data types.
Definition: angles.hpp:26