Mathematical constants¶
Defined in header <Kokkos_MathematicalConstants.hpp>
which is included from <Kokkos_Core.hpp>
Provides all mathematical constants from <numbers> (since C++20).
All constants are defined in the Kokkos::numbers:: namespace since version 4.0, in Kokkos::Experimental in previous versions.
Variable Templates¶
The following are variable templates defined for standard floating-point types (float, double, long double).
Template name |
Math symbol |
Description |
|---|---|---|
|
\(e\) |
Base of the natural logarithm |
|
\(\log_{2}{e}\) |
Base-2 logarithm of e |
|
\(\log_{10}{e}\) |
Base-10 logarithm of e |
|
\(\pi\) |
Ratio of a circle’s circumference to its diameter |
|
\(\frac{1}{\pi}\) |
Inverse of pi |
|
\(\frac{1}{\sqrt{\pi}}\) |
Inverse of the square root of pi |
|
\(\ln{2}\) |
Natural logarithm of 2 |
|
\(\ln{10}\) |
Natural logarithm of 10 |
|
\(\sqrt{2}\) |
Square root of 2 |
|
\(\sqrt{3}\) |
Square root of 3 |
|
\(\frac{1}{\sqrt{3}}\) |
Inverse of the square root of 3 |
|
\(\gamma\) |
Euler-Mascheroni constant |
|
\(\varphi\) |
Golden ratio constant \(\frac{1+\sqrt{5}}{2}\) |
Convenience Constants (double)¶
For each variable template listed above, Kokkos provides an inline constexpr
double constant without the _v suffix. These are shorthand for the
double specialization.
Kokkos::numbers::piis equivalent toKokkos::numbers::pi_v<double>Kokkos::numbers::eis equivalent toKokkos::numbers::e_v<double>
Notes¶
The mathematical constants are available in
Kokkos::Experimental::since Kokkos 3.6They were “promoted” to the
Kokkos::numbersnamespace in 4.0 and removed fromKokkos::Experimental::in 4.3Passing mathematical constants by reference or taking their address in device code is not supported by some toolchains and hence not portable. (See known issues)
Support for quadruple precision floating-point
__float128can be enabled via-DKokkos_ENABLE_LIBQUADMATH=ON.
Example¶
KOKKOS_FUNCTION void example() {
constexpr auto pi = Kokkos::numbers::pi_v<float>;
auto const x = Kokkos::sin(pi/6);
}