Numeric traits ============== .. role::cpp(code) :language: cpp .. role:: strike :class: strike .. _KokkosNumericTraits: https://github.com/kokkos/kokkos/blob/3.5.00/core/src/Kokkos_NumericTraits.hpp .. |KokkosNumericTraits| replace:: ```` Defined in header |KokkosNumericTraits|_ which is included from ```` .. _NumericLimits: https://en.cppreference.com/w/cpp/types/numeric_limits .. |NumericLimits| replace:: ``numeric_limits`` from the standard library header ```` .. _P1841 : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1841r2.pdf .. |P1841| replace:: P1841 Provides a replacement for |NumericLimits|_. 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 :strike:`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*`` :strike:`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 | +=========================================================+================================================+ | ``std::numeric_limits::min()`` | ``finite_min_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::min()`` | ``norm_min_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::lowest()`` | ``finite_min_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::max()`` | ``finite_max_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::epsilon()`` | ``epsilon_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::round_error()`` | ``round_error_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::infinity()`` | ``infinity_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::quiet_NaN()`` | ``quiet_NaN_v`` (since 3.6) | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::signaling_NaN()`` | ``signaling_NaN_v`` (since 3.6) | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::denorm_min()`` | ``denorm_min_v`` (since 3.6) | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::digits`` | ``digits_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::digits10`` | ``digits10_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::max_digits10`` | ``max_digits10_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::radix`` | ``radix_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::min_exponent`` | ``min_exponent_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::min_exponent10`` | ``min_exponent10_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::max_exponent`` | ``max_exponent_v`` | +---------------------------------------------------------+------------------------------------------------+ | ``std::numeric_limits::max_exponent10`` | ``max_exponent10_v`` | +---------------------------------------------------------+------------------------------------------------+ Individual traits have ``value`` member constant that can be used with C++14 (e.g. ``epsilon::value``). ------------ Individual traits are SFINAE-friendly, you can detect value presence/absence. .. code-block:: cpp template constexpr auto has_infinity(T) -> decltype(Kokkos::Experimental::infinity::value, std::true_type{}) { return {}; } constexpr std::false_type has_infinity(...) { return {}; } template KOKKOS_FUNCTION constexpr std::enable_if_t legacy_std_numeric_limits_infinity() { return Kokkos::Experimental::infinity::value; } template KOKKOS_FUNCTION constexpr std::enable_if_t legacy_std_numeric_limits_infinity() { return T(); } ------------ **See also** .. _MathematicalConstants : mathematical-constants.html .. |MathematicalConstants| replace:: Mathematical constants .. _CommonMathematicalFunctions : mathematical-functions.html .. |CommonMathematicalFunctions| replace:: Common mathematical functions |MathematicalConstants|_ |CommonMathematicalFunctions|_