xref: /netbsd-src/external/gpl3/gcc/dist/libstdc++-v3/include/std/numbers (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1fb8a8121Smrg// <numbers> -*- C++ -*-
2fb8a8121Smrg
3*b1e83836Smrg// Copyright (C) 2019-2022 Free Software Foundation, Inc.
4fb8a8121Smrg//
5fb8a8121Smrg// This file is part of the GNU ISO C++ Library.  This library is free
6fb8a8121Smrg// software; you can redistribute it and/or modify it under the
7fb8a8121Smrg// terms of the GNU General Public License as published by the
8fb8a8121Smrg// Free Software Foundation; either version 3, or (at your option)
9fb8a8121Smrg// any later version.
10fb8a8121Smrg
11fb8a8121Smrg// This library is distributed in the hope that it will be useful,
12fb8a8121Smrg// but WITHOUT ANY WARRANTY; without even the implied warranty of
13fb8a8121Smrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14fb8a8121Smrg// GNU General Public License for more details.
15fb8a8121Smrg
16fb8a8121Smrg// Under Section 7 of GPL version 3, you are granted additional
17fb8a8121Smrg// permissions described in the GCC Runtime Library Exception, version
18fb8a8121Smrg// 3.1, as published by the Free Software Foundation.
19fb8a8121Smrg
20fb8a8121Smrg// You should have received a copy of the GNU General Public License and
21fb8a8121Smrg// a copy of the GCC Runtime Library Exception along with this program;
22fb8a8121Smrg// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23fb8a8121Smrg// <http://www.gnu.org/licenses/>.
24fb8a8121Smrg
25fb8a8121Smrg/** @file include/numbers
26fb8a8121Smrg *  This is a Standard C++ Library header.
27fb8a8121Smrg */
28fb8a8121Smrg
29fb8a8121Smrg#ifndef _GLIBCXX_NUMBERS
30fb8a8121Smrg#define _GLIBCXX_NUMBERS 1
31fb8a8121Smrg
32fb8a8121Smrg#pragma GCC system_header
33fb8a8121Smrg
34fb8a8121Smrg#if __cplusplus > 201703L
35fb8a8121Smrg
36fb8a8121Smrg#include <type_traits>
37fb8a8121Smrg
38fb8a8121Smrgnamespace std _GLIBCXX_VISIBILITY(default)
39fb8a8121Smrg{
40fb8a8121Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION
41fb8a8121Smrg
42fb8a8121Smrg/** @defgroup math_constants Mathematical constants
43fb8a8121Smrg *  @ingroup numerics
44fb8a8121Smrg *  @{
45fb8a8121Smrg */
46fb8a8121Smrg
47fb8a8121Smrg/// Namespace for mathematical constants
48fb8a8121Smrgnamespace numbers
49fb8a8121Smrg{
50fb8a8121Smrg#define __cpp_lib_math_constants 201907L
51fb8a8121Smrg
52fb8a8121Smrg  /// @cond undoc
53fb8a8121Smrg  template<typename _Tp>
54fb8a8121Smrg    using _Enable_if_floating = enable_if_t<is_floating_point_v<_Tp>, _Tp>;
55fb8a8121Smrg  /// @endcond
56fb8a8121Smrg
57fb8a8121Smrg  /// e
58fb8a8121Smrg  template<typename _Tp>
59fb8a8121Smrg    inline constexpr _Tp e_v
60fb8a8121Smrg      = _Enable_if_floating<_Tp>(2.718281828459045235360287471352662498L);
61fb8a8121Smrg
62fb8a8121Smrg  /// log_2 e
63fb8a8121Smrg  template<typename _Tp>
64fb8a8121Smrg    inline constexpr _Tp log2e_v
65fb8a8121Smrg      = _Enable_if_floating<_Tp>(1.442695040888963407359924681001892137L);
66fb8a8121Smrg
67fb8a8121Smrg  /// log_10 e
68fb8a8121Smrg  template<typename _Tp>
69fb8a8121Smrg    inline constexpr _Tp log10e_v
70fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.434294481903251827651128918916605082L);
71fb8a8121Smrg
72fb8a8121Smrg  /// pi
73fb8a8121Smrg  template<typename _Tp>
74fb8a8121Smrg    inline constexpr _Tp pi_v
75fb8a8121Smrg      = _Enable_if_floating<_Tp>(3.141592653589793238462643383279502884L);
76fb8a8121Smrg
77fb8a8121Smrg  /// 1/pi
78fb8a8121Smrg  template<typename _Tp>
79fb8a8121Smrg    inline constexpr _Tp inv_pi_v
80fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.318309886183790671537767526745028724L);
81fb8a8121Smrg
82fb8a8121Smrg  /// 1/sqrt(pi)
83fb8a8121Smrg  template<typename _Tp>
84fb8a8121Smrg    inline constexpr _Tp inv_sqrtpi_v
85fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.564189583547756286948079451560772586L);
86fb8a8121Smrg
87fb8a8121Smrg  /// log_e 2
88fb8a8121Smrg  template<typename _Tp>
89fb8a8121Smrg    inline constexpr _Tp ln2_v
90fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.693147180559945309417232121458176568L);
91fb8a8121Smrg
92fb8a8121Smrg  /// log_e 10
93fb8a8121Smrg  template<typename _Tp>
94fb8a8121Smrg    inline constexpr _Tp ln10_v
95fb8a8121Smrg      = _Enable_if_floating<_Tp>(2.302585092994045684017991454684364208L);
96fb8a8121Smrg
97fb8a8121Smrg  /// sqrt(2)
98fb8a8121Smrg  template<typename _Tp>
99fb8a8121Smrg    inline constexpr _Tp sqrt2_v
100fb8a8121Smrg      = _Enable_if_floating<_Tp>(1.414213562373095048801688724209698079L);
101fb8a8121Smrg
102fb8a8121Smrg  /// sqrt(3)
103fb8a8121Smrg  template<typename _Tp>
104fb8a8121Smrg    inline constexpr _Tp sqrt3_v
105fb8a8121Smrg      = _Enable_if_floating<_Tp>(1.732050807568877293527446341505872367L);
106fb8a8121Smrg
107fb8a8121Smrg  /// 1/sqrt(3)
108fb8a8121Smrg  template<typename _Tp>
109fb8a8121Smrg    inline constexpr _Tp inv_sqrt3_v
110fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.577350269189625764509148780501957456L);
111fb8a8121Smrg
112fb8a8121Smrg  /// The Euler-Mascheroni constant
113fb8a8121Smrg  template<typename _Tp>
114fb8a8121Smrg    inline constexpr _Tp egamma_v
115fb8a8121Smrg      = _Enable_if_floating<_Tp>(0.577215664901532860606512090082402431L);
116fb8a8121Smrg
117fb8a8121Smrg  /// The golden ratio, (1+sqrt(5))/2
118fb8a8121Smrg  template<typename _Tp>
119fb8a8121Smrg    inline constexpr _Tp phi_v
120fb8a8121Smrg      = _Enable_if_floating<_Tp>(1.618033988749894848204586834365638118L);
121fb8a8121Smrg
122fb8a8121Smrg  inline constexpr double e = e_v<double>;
123fb8a8121Smrg  inline constexpr double log2e = log2e_v<double>;
124fb8a8121Smrg  inline constexpr double log10e = log10e_v<double>;
125fb8a8121Smrg  inline constexpr double pi = pi_v<double>;
126fb8a8121Smrg  inline constexpr double inv_pi = inv_pi_v<double>;
127fb8a8121Smrg  inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
128fb8a8121Smrg  inline constexpr double ln2 = ln2_v<double>;
129fb8a8121Smrg  inline constexpr double ln10 = ln10_v<double>;
130fb8a8121Smrg  inline constexpr double sqrt2 = sqrt2_v<double>;
131fb8a8121Smrg  inline constexpr double sqrt3 = sqrt3_v<double>;
132fb8a8121Smrg  inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
133fb8a8121Smrg  inline constexpr double egamma = egamma_v<double>;
134fb8a8121Smrg  inline constexpr double phi = phi_v<double>;
135fb8a8121Smrg
136fb8a8121Smrg#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
137fb8a8121Smrg  template<>
138fb8a8121Smrg    inline constexpr __float128 e_v<__float128>
139fb8a8121Smrg      = 2.718281828459045235360287471352662498Q;
140fb8a8121Smrg
141fb8a8121Smrg  /// log_2 e
142fb8a8121Smrg  template<>
143fb8a8121Smrg    inline constexpr __float128 log2e_v<__float128>
144fb8a8121Smrg      = 1.442695040888963407359924681001892137Q;
145fb8a8121Smrg
146fb8a8121Smrg  /// log_10 e
147fb8a8121Smrg  template<>
148fb8a8121Smrg    inline constexpr __float128 log10e_v<__float128>
149fb8a8121Smrg      = 0.434294481903251827651128918916605082Q;
150fb8a8121Smrg
151fb8a8121Smrg  /// pi
152fb8a8121Smrg  template<>
153fb8a8121Smrg    inline constexpr __float128 pi_v<__float128>
154fb8a8121Smrg      = 3.141592653589793238462643383279502884Q;
155fb8a8121Smrg
156fb8a8121Smrg  /// 1/pi
157fb8a8121Smrg  template<>
158fb8a8121Smrg    inline constexpr __float128 inv_pi_v<__float128>
159fb8a8121Smrg      = 0.318309886183790671537767526745028724Q;
160fb8a8121Smrg
161fb8a8121Smrg  /// 1/sqrt(pi)
162fb8a8121Smrg  template<>
163fb8a8121Smrg    inline constexpr __float128 inv_sqrtpi_v<__float128>
164fb8a8121Smrg      = 0.564189583547756286948079451560772586Q;
165fb8a8121Smrg
166fb8a8121Smrg  /// log_e 2
167fb8a8121Smrg  template<>
168fb8a8121Smrg    inline constexpr __float128 ln2_v<__float128>
169fb8a8121Smrg      = 0.693147180559945309417232121458176568Q;
170fb8a8121Smrg
171fb8a8121Smrg  /// log_e 10
172fb8a8121Smrg  template<>
173fb8a8121Smrg    inline constexpr __float128 ln10_v<__float128>
174fb8a8121Smrg      = 2.302585092994045684017991454684364208Q;
175fb8a8121Smrg
176fb8a8121Smrg  /// sqrt(2)
177fb8a8121Smrg  template<>
178fb8a8121Smrg    inline constexpr __float128 sqrt2_v<__float128>
179fb8a8121Smrg      = 1.414213562373095048801688724209698079Q;
180fb8a8121Smrg
181fb8a8121Smrg  /// sqrt(3)
182fb8a8121Smrg  template<>
183fb8a8121Smrg    inline constexpr __float128 sqrt3_v<__float128>
184fb8a8121Smrg      = 1.732050807568877293527446341505872367Q;
185fb8a8121Smrg
186fb8a8121Smrg  /// 1/sqrt(3)
187fb8a8121Smrg  template<>
188fb8a8121Smrg    inline constexpr __float128 inv_sqrt3_v<__float128>
189fb8a8121Smrg      = 0.577350269189625764509148780501957456Q;
190fb8a8121Smrg
191fb8a8121Smrg  /// The Euler-Mascheroni constant
192fb8a8121Smrg  template<>
193fb8a8121Smrg    inline constexpr __float128 egamma_v<__float128>
194fb8a8121Smrg      = 0.577215664901532860606512090082402431Q;
195fb8a8121Smrg
196fb8a8121Smrg  /// The golden ratio, (1+sqrt(5))/2
197fb8a8121Smrg  template<>
198fb8a8121Smrg    inline constexpr __float128 phi_v<__float128>
199fb8a8121Smrg      = 1.618033988749894848204586834365638118Q;
200fb8a8121Smrg#endif // USE_FLOAT128
201fb8a8121Smrg
202fb8a8121Smrg} // namespace numbers
203fb8a8121Smrg/// @}
204fb8a8121Smrg_GLIBCXX_END_NAMESPACE_VERSION
205fb8a8121Smrg} // namespace std
206fb8a8121Smrg
207fb8a8121Smrg#endif // C++20
208fb8a8121Smrg#endif // _GLIBCXX_NUMBERS
209