Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
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
31namespace 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
50KOKKOS_IMPL_DEFINE_TRAIT(infinity, infinity(), floating_point)
51KOKKOS_IMPL_DEFINE_TRAIT(finite_min, lowest(), arithmetic )
52KOKKOS_IMPL_DEFINE_TRAIT(finite_max, max(), arithmetic )
53KOKKOS_IMPL_DEFINE_TRAIT(epsilon, epsilon(), floating_point)
54KOKKOS_IMPL_DEFINE_TRAIT(round_error, round_error(), floating_point)
55KOKKOS_IMPL_DEFINE_TRAIT(norm_min, min(), floating_point)
56KOKKOS_IMPL_DEFINE_TRAIT(denorm_min, denorm_min(), floating_point)
57KOKKOS_IMPL_DEFINE_TRAIT(quiet_NaN, quiet_NaN(), floating_point)
58KOKKOS_IMPL_DEFINE_TRAIT(signaling_NaN, signaling_NaN(), floating_point)
59
60// Numeric characteristics traits
61KOKKOS_IMPL_DEFINE_TRAIT(digits, digits, arithmetic )
62KOKKOS_IMPL_DEFINE_TRAIT(digits10, digits10, arithmetic )
63KOKKOS_IMPL_DEFINE_TRAIT(max_digits10, max_digits10, floating_point)
64KOKKOS_IMPL_DEFINE_TRAIT(radix, radix, arithmetic )
65KOKKOS_IMPL_DEFINE_TRAIT(min_exponent, min_exponent, floating_point)
66KOKKOS_IMPL_DEFINE_TRAIT(min_exponent10, min_exponent10, floating_point)
67KOKKOS_IMPL_DEFINE_TRAIT(max_exponent, max_exponent, floating_point)
68KOKKOS_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