1 /* 2 * Copyright (c) 2020, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes definitions for numeric limits. 32 */ 33 34 #ifndef NUMERIC_LIMITS_HPP_ 35 #define NUMERIC_LIMITS_HPP_ 36 37 #include <stdint.h> 38 39 namespace ot { 40 41 /** 42 * Provides a way to query properties of arithmetic types. 43 * 44 * There are no members if `Type` is not a supported arithmetic type. 45 * 46 */ 47 template <typename Type> struct NumericLimits 48 { 49 }; 50 51 // Specialization for different integral types. 52 53 template <> struct NumericLimits<int8_t> 54 { 55 static constexpr int8_t kMin = INT8_MIN; 56 static constexpr int8_t kMax = INT8_MAX; 57 }; 58 59 template <> struct NumericLimits<int16_t> 60 { 61 static constexpr int16_t kMin = INT16_MIN; 62 static constexpr int16_t kMax = INT16_MAX; 63 }; 64 65 template <> struct NumericLimits<int32_t> 66 { 67 static constexpr int32_t kMin = INT32_MIN; 68 static constexpr int32_t kMax = INT32_MAX; 69 }; 70 71 template <> struct NumericLimits<int64_t> 72 { 73 static constexpr int64_t kMin = INT64_MIN; 74 static constexpr int64_t kMax = INT64_MAX; 75 }; 76 77 template <> struct NumericLimits<uint8_t> 78 { 79 static constexpr uint8_t kMin = 0; 80 static constexpr uint8_t kMax = UINT8_MAX; 81 }; 82 83 template <> struct NumericLimits<uint16_t> 84 { 85 static constexpr uint16_t kMin = 0; 86 static constexpr uint16_t kMax = UINT16_MAX; 87 }; 88 89 template <> struct NumericLimits<uint32_t> 90 { 91 static constexpr uint32_t kMin = 0; 92 static constexpr uint32_t kMax = UINT32_MAX; 93 }; 94 95 template <> struct NumericLimits<uint64_t> 96 { 97 static constexpr uint64_t kMin = 0; 98 static constexpr uint64_t kMax = UINT64_MAX; 99 }; 100 101 } // namespace ot 102 103 #endif // NUMERIC_LIMITS_HPP_ 104