Numeric traits#
Defined in header <Kokkos_NumericTraits.hpp>
which is included from <Kokkos_Core.hpp>
Provides a replacement for numeric_limits
from the standard library header <limits>
. Implements a new facility that is being added to the C++23 standard library and that
breaks the monolithic numeric_limits
class template apart into individual
trait templates. For details, please refer to P1841.
Numeric traits are defined in the Kokkos::Experimental
namespace since Kokkos 3.5
See below the list of available traits.
trait*
denotes traits that were added in Kokkos 3.6
trait* denotes traits that were removed in Kokkos 4.0
Numeric distinguished value traits
infinity
finite_min
finite_max
epsilon
round_error
norm_min
denorm_min*
reciprocal_overflow_threshold*
quiet_NaN*
signaling_NaN*
Numeric characteristics traits
digits
digits10
max_digits10
radix
min_exponent
min_exponent10
max_exponent
max_exponent10
Standard library |
Kokkos with C++17 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Individual traits have value
member constant that can be used with C++14 (e.g. epsilon<float>::value
).
Individual traits are SFINAE-friendly, you can detect value presence/absence.
template <class T>
constexpr auto has_infinity(T)
-> decltype(Kokkos::Experimental::infinity<T>::value, std::true_type{}) {
return {};
}
constexpr std::false_type has_infinity(...) { return {}; }
template <class T>
KOKKOS_FUNCTION constexpr std::enable_if_t<has_infinity(T{}), T>
legacy_std_numeric_limits_infinity() {
return Kokkos::Experimental::infinity<T>::value;
}
template <class T>
KOKKOS_FUNCTION constexpr std::enable_if_t<!has_infinity(T{}), T>
legacy_std_numeric_limits_infinity() {
return T();
}
See also