Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
math_constants.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "types.hpp"
4#include <numbers>
5
6namespace uni20
7{
8namespace detail
9{
10template <class T> struct math_constants
11{};
12
13template <class T>
14 requires(std::same_as<T, float> || std::same_as<T, double> || std::same_as<T, long double>
15#if UNI20_HAS_FLOAT128
16 || std::same_as<T, float128>
17#endif
18 )
19struct math_constants<T>
20{
21 static constexpr T pi = std::numbers::pi_v<T>;
22 static constexpr T log_two = std::numbers::ln2_v<T>;
23 static constexpr T euler_gamma = std::numbers::egamma_v<T>;
24 // First 128 binary fractional bits, generated with a 512-bit oracle.
25 // Integer chunks and binary scales avoid a narrower floating intermediate.
26 // The resulting rounding is verified for every configured native format.
27 static constexpr T catalan = T(0xea7cb89f409ae845ULL) * T(0x1p-64L) + T(0x215822e37d32d0c6ULL) * T(0x1p-128L);
28};
29} // namespace detail
30
35template <class Real>
36 requires requires { detail::math_constants<Real>::pi; }
37inline constexpr auto pi = detail::math_constants<Real>::pi;
38
40template <class Real>
41 requires requires { detail::math_constants<Real>::log_two; }
42inline constexpr auto log_two = detail::math_constants<Real>::log_two;
43
45template <class Real>
46 requires requires { detail::math_constants<Real>::euler_gamma; }
47inline constexpr auto euler_gamma = detail::math_constants<Real>::euler_gamma;
48
50template <class Real>
51 requires requires { detail::math_constants<Real>::catalan; }
52inline constexpr auto catalan = detail::math_constants<Real>::catalan;
53} // namespace uni20
Definition async/async.hpp:26
constexpr auto pi
Pi as a native constant or a precision-aware MPFR descriptor.
Definition math_constants.hpp:37
constexpr auto euler_gamma
Euler-Mascheroni constant, with the same type and precision rules as pi.
Definition math_constants.hpp:47
constexpr auto catalan
Catalan constant as a native value or a precision-aware MPFR descriptor.
Definition math_constants.hpp:52
constexpr auto log_two
Natural logarithm of two, with the same type and precision rules as pi.
Definition math_constants.hpp:42