Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_NumericTraits.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 
17 #ifndef KOKKOS_NUMERIC_TRAITS_HPP
18 #define KOKKOS_NUMERIC_TRAITS_HPP
19 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE
21 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_NUMERIC_TRAITS
22 #endif
23 
24 #include <Kokkos_Macros.hpp>
25 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
26 #include <Kokkos_ReductionIdentity.hpp>
27 #endif
28 #include <type_traits>
29 #include <limits>
30 
31 namespace Kokkos::Experimental {
32 
33 #define KOKKOS_IMPL_DEFINE_TRAIT(TRAIT, NUMERIC_LIMITS_MEMBER, CONSTRAINT) \
34  namespace Impl { \
35  template <class T, class Enable = void> \
36  struct TRAIT##_helper {}; \
37  template <class T> \
38  struct TRAIT##_helper<T, std::enable_if_t<std::is_##CONSTRAINT##_v<T>>> { \
39  static constexpr auto value = \
40  std::numeric_limits<T>::NUMERIC_LIMITS_MEMBER; \
41  }; \
42  } \
43  template <class T> \
44  struct TRAIT : Impl::TRAIT##_helper<T> {}; \
45  template <class T> \
46  inline constexpr auto TRAIT##_v = TRAIT<T>::value;
47 
48 // clang-format off
49 // Numeric distinguished value traits
50 KOKKOS_IMPL_DEFINE_TRAIT(infinity, infinity(), floating_point)
51 KOKKOS_IMPL_DEFINE_TRAIT(finite_min, lowest(), arithmetic )
52 KOKKOS_IMPL_DEFINE_TRAIT(finite_max, max(), arithmetic )
53 KOKKOS_IMPL_DEFINE_TRAIT(epsilon, epsilon(), floating_point)
54 KOKKOS_IMPL_DEFINE_TRAIT(round_error, round_error(), floating_point)
55 KOKKOS_IMPL_DEFINE_TRAIT(norm_min, min(), floating_point)
56 KOKKOS_IMPL_DEFINE_TRAIT(denorm_min, denorm_min(), floating_point)
57 KOKKOS_IMPL_DEFINE_TRAIT(quiet_NaN, quiet_NaN(), floating_point)
58 KOKKOS_IMPL_DEFINE_TRAIT(signaling_NaN, signaling_NaN(), floating_point)
59 
60 // Numeric characteristics traits
61 KOKKOS_IMPL_DEFINE_TRAIT(digits, digits, arithmetic )
62 KOKKOS_IMPL_DEFINE_TRAIT(digits10, digits10, arithmetic )
63 KOKKOS_IMPL_DEFINE_TRAIT(max_digits10, max_digits10, floating_point)
64 KOKKOS_IMPL_DEFINE_TRAIT(radix, radix, arithmetic )
65 KOKKOS_IMPL_DEFINE_TRAIT(min_exponent, min_exponent, floating_point)
66 KOKKOS_IMPL_DEFINE_TRAIT(min_exponent10, min_exponent10, floating_point)
67 KOKKOS_IMPL_DEFINE_TRAIT(max_exponent, max_exponent, floating_point)
68 KOKKOS_IMPL_DEFINE_TRAIT(max_exponent10, max_exponent10, floating_point)
69 // clang-format on
70 
71 #undef KOKKOS_IMPL_DEFINE_TRAIT
72 
73 } // namespace Kokkos::Experimental
74 
75 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_NUMERIC_TRAITS
76 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
77 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_NUMERIC_TRAITS
78 #endif
79 #endif