Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_MathematicalConstants.hpp
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 #ifndef KOKKOS_MATHEMATICAL_CONSTANTS_HPP
17 #define KOKKOS_MATHEMATICAL_CONSTANTS_HPP
18 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
19 #define KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_MATHCONSTANTS
21 #endif
22 
23 #include <Kokkos_Macros.hpp>
24 #include <type_traits>
25 
26 namespace Kokkos::numbers {
27 
28 #define KOKKOS_IMPL_MATH_CONSTANT(TRAIT, VALUE) \
29  template <class T> \
30  inline constexpr auto TRAIT##_v = \
31  std::enable_if_t<std::is_floating_point_v<T>, T>(VALUE); \
32  inline constexpr auto TRAIT = TRAIT##_v<double>
33 
34 // clang-format off
35 KOKKOS_IMPL_MATH_CONSTANT(e, 2.718281828459045235360287471352662498L);
36 KOKKOS_IMPL_MATH_CONSTANT(log2e, 1.442695040888963407359924681001892137L);
37 KOKKOS_IMPL_MATH_CONSTANT(log10e, 0.434294481903251827651128918916605082L);
38 KOKKOS_IMPL_MATH_CONSTANT(pi, 3.141592653589793238462643383279502884L);
39 KOKKOS_IMPL_MATH_CONSTANT(inv_pi, 0.318309886183790671537767526745028724L);
40 KOKKOS_IMPL_MATH_CONSTANT(inv_sqrtpi, 0.564189583547756286948079451560772586L);
41 KOKKOS_IMPL_MATH_CONSTANT(ln2, 0.693147180559945309417232121458176568L);
42 KOKKOS_IMPL_MATH_CONSTANT(ln10, 2.302585092994045684017991454684364208L);
43 KOKKOS_IMPL_MATH_CONSTANT(sqrt2, 1.414213562373095048801688724209698079L);
44 KOKKOS_IMPL_MATH_CONSTANT(sqrt3, 1.732050807568877293527446341505872367L);
45 KOKKOS_IMPL_MATH_CONSTANT(inv_sqrt3, 0.577350269189625764509148780501957456L);
46 KOKKOS_IMPL_MATH_CONSTANT(egamma, 0.577215664901532860606512090082402431L);
47 KOKKOS_IMPL_MATH_CONSTANT(phi, 1.618033988749894848204586834365638118L);
48 // clang-format on
49 
50 #undef KOKKOS_IMPL_MATH_CONSTANT
51 
52 } // namespace Kokkos::numbers
53 
54 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_MATHCONSTANTS
55 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
56 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_MATHCONSTANTS
57 #endif
58 #endif