| 1 | // |
| 2 | // SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | // |
| 4 | // SPDX-License-Identifier: Apache-2.0 |
| 5 | // |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <limits> |
| 10 | #include <type_traits> |
| 11 | |
| 12 | #include "test/common/bfloat16.hpp" |
| 13 | #include "test/common/float16.hpp" |
| 14 | #include "test/common/int2.hpp" |
| 15 | #include "test/common/int4.hpp" |
| 16 | |
| 17 | namespace kai::test { |
| 18 | |
| 19 | /// Highest finite value of type `T`. |
| 20 | template <typename T> |
| 21 | inline constexpr std::enable_if_t<std::is_arithmetic_v<T>, T> numeric_highest = std::numeric_limits<T>::max(); |
| 22 | |
| 23 | /// Highest finite value of @ref UInt4. |
| 24 | template <> |
| 25 | inline constexpr UInt4 numeric_highest<UInt4>{15}; |
| 26 | |
| 27 | /// Highest finite value of @ref Int4. |
| 28 | template <> |
| 29 | inline constexpr Int4 numeric_highest<Int4>{7}; |
| 30 | |
| 31 | /// Highest finite value of @ref UInt2. |
| 32 | template <> |
| 33 | inline constexpr UInt2 numeric_highest<UInt2>{3}; |
| 34 | |
| 35 | /// Highest finite value of @ref Int2. |
| 36 | template <> |
| 37 | inline constexpr Int2 numeric_highest<Int2>{1}; |
| 38 | |
| 39 | /// Highest finite value of @ref Float16. |
| 40 | template <> |
| 41 | inline constexpr Float16 numeric_highest<Float16> = Float16::from_binary(0x7bff); |
| 42 | |
| 43 | /// Highest finite value of @ref BFloat16. |
| 44 | template <> |
| 45 | inline constexpr BFloat16 numeric_highest<BFloat16<>> = BFloat16<>::from_binary(0x7f7f); |
| 46 | |
| 47 | /// Lowest finite value of type `T`. |
| 48 | template <typename T> |
| 49 | inline constexpr std::enable_if_t<std::is_arithmetic_v<T>, T> numeric_lowest = std::numeric_limits<T>::lowest(); |
| 50 | |
| 51 | /// Lowest finite value of @ref UInt2. |
| 52 | template <> |
| 53 | inline constexpr UInt2 numeric_lowest<UInt2>{0}; |
| 54 | |
| 55 | /// Lowest finite value of @ref Int2. |
| 56 | template <> |
| 57 | inline constexpr Int2 numeric_lowest<Int2>{-2}; |
| 58 | |
| 59 | /// Lowest finite value of @ref UInt4. |
| 60 | template <> |
| 61 | inline constexpr UInt4 numeric_lowest<UInt4>{0}; |
| 62 | |
| 63 | /// Lowest finite value of @ref Int4. |
| 64 | template <> |
| 65 | inline constexpr Int4 numeric_lowest<Int4>{-8}; |
| 66 | |
| 67 | /// Lowest finite value of @ref Float16. |
| 68 | template <> |
| 69 | inline constexpr Float16 numeric_lowest<Float16> = Float16::from_binary(0xfbff); |
| 70 | |
| 71 | /// Lowest finite value of @ref BFloat16. |
| 72 | template <> |
| 73 | inline constexpr BFloat16 numeric_lowest<BFloat16<>> = BFloat16<>::from_binary(0xff7f); |
| 74 | |
| 75 | } // namespace kai::test |