-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers
More file actions
120 lines (105 loc) · 6.54 KB
/
numbers
File metadata and controls
120 lines (105 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Reference implementation of the <numbers> header for https://wg21.link/P0631.
Copyright © 2019 Lev Minkovsky
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifdef __cpp_variable_templates
#if __has_include(<concepts>)
#include <concepts>
#define __cpp_lib_math_constants 201907L
#elif defined(__cpp_concepts)
#include <type_traits>
template<class T> concept floating_point = std::is_floating_point_v<T>;
#define __cpp_lib_math_constants 201907L
#endif
#ifdef __cpp_inline_variables
#define __INLINE inline
#else
#define __INLINE
#endif
namespace std {
namespace numbers {
template<typename> __INLINE constexpr bool __always_false = false;
template<typename T> __INLINE constexpr T __invalidTemplate() {
static_assert(__always_false<T>, "This template needs to be specialized."); return T();
}
template <typename T> __INLINE constexpr T e_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T log2e_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T log10e_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T pi_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T inv_pi_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T inv_sqrtpi_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T ln2_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T ln10_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T sqrt2_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T sqrt3_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T inv_sqrt3_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T egamma_v = __invalidTemplate<T>();
template <typename T> __INLINE constexpr T phi_v = __invalidTemplate<T>();
#ifdef __cpp_lib_math_constants
template <floating_point T> __INLINE constexpr T e_v<T> = (T)2.718281828459045235360287471352662498L;
template <floating_point T> __INLINE constexpr T log2e_v<T> = (T)1.442695040888963407359924681001892137L;
template <floating_point T> __INLINE constexpr T log10e_v<T> = (T)0.434294481903251827651128918916605082L;
template <floating_point T> __INLINE constexpr T pi_v<T> = (T)3.141592653589793238462643383279502884L;
template <floating_point T> __INLINE constexpr T inv_pi_v<T> = (T)0.318309886183790671537767526745028724L;
template <floating_point T> __INLINE constexpr T inv_sqrtpi_v<T> = (T)0.564189583547756286948079451560772586L;
template <floating_point T> __INLINE constexpr T ln2_v<T> = (T)0.693147180559945309417232121458176568L;
template <floating_point T> __INLINE constexpr T ln10_v<T> = (T)2.302585092994045684017991454684364208L;
template <floating_point T> __INLINE constexpr T sqrt2_v<T> = (T)1.414213562373095048801688724209698078L;
template <floating_point T> __INLINE constexpr T sqrt3_v<T> = (T)1.732050807568877293527446341505872366L;
template <floating_point T> __INLINE constexpr T inv_sqrt3_v<T> = (T)0.577350269189625764509148780501957456L;
template <floating_point T> __INLINE constexpr T egamma_v<T> = (T)0.577215664901532860606512090082402431L;
template <floating_point T> __INLINE constexpr T phi_v<T> = (T)1.618033988749894848204586834365638117L;
#else
#define MATH_CONSTANT_DEF(name,value) \
template <> __INLINE constexpr float name<float> = (float)value; \
template <> __INLINE constexpr double name<double> = (double)value; \
template <> __INLINE constexpr long double name<long double> = (long double)value;
MATH_CONSTANT_DEF(e_v, 2.718281828459045235360287471352662498L)
MATH_CONSTANT_DEF(log2e_v, 1.442695040888963407359924681001892137L)
MATH_CONSTANT_DEF(log10e_v, 0.434294481903251827651128918916605082L)
MATH_CONSTANT_DEF(pi_v, 3.141592653589793238462643383279502884L)
MATH_CONSTANT_DEF(inv_pi_v, 0.318309886183790671537767526745028724L)
MATH_CONSTANT_DEF(inv_sqrtpi_v, 0.564189583547756286948079451560772586L)
MATH_CONSTANT_DEF(ln2_v, 0.693147180559945309417232121458176568L)
MATH_CONSTANT_DEF(ln10_v, 2.302585092994045684017991454684364208L)
MATH_CONSTANT_DEF(sqrt2_v, 1.414213562373095048801688724209698078L)
MATH_CONSTANT_DEF(sqrt3_v, 1.732050807568877293527446341505872366L)
MATH_CONSTANT_DEF(inv_sqrt3_v, 0.577350269189625764509148780501957456L)
MATH_CONSTANT_DEF(egamma_v, 0.577215664901532860606512090082402431L)
MATH_CONSTANT_DEF(phi_v, 1.618033988749894848204586834365638117L)
#undef MATH_CONSTANT_DEF
#define __cpp_lib_math_constants 201907L
#endif
__INLINE constexpr double e = e_v<double>;
__INLINE constexpr double log2e = log2e_v<double>;
__INLINE constexpr double log10e = log10e_v<double>;
__INLINE constexpr double pi = pi_v<double>;
__INLINE constexpr double inv_pi = inv_pi_v<double>;
__INLINE constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
__INLINE constexpr double ln2 = ln2_v<double>;
__INLINE constexpr double ln10 = ln10_v<double>;
__INLINE constexpr double sqrt2 = sqrt2_v<double>;
__INLINE constexpr double sqrt3 = sqrt3_v<double>;
__INLINE constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
__INLINE constexpr double egamma = egamma_v<double>;
__INLINE constexpr double phi = phi_v<double>;
}
}
#undef __INLINE
#endif