Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_NUMERICS_SAFE_MATH_IMPL_H_ | 5 #ifndef BASE_NUMERICS_SAFE_MATH_IMPL_H_ |
| 6 #define BASE_NUMERICS_SAFE_MATH_IMPL_H_ | 6 #define BASE_NUMERICS_SAFE_MATH_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 struct IntegerForSizeAndSign<4, false> { | 50 struct IntegerForSizeAndSign<4, false> { |
| 51 typedef uint32_t type; | 51 typedef uint32_t type; |
| 52 }; | 52 }; |
| 53 template <> | 53 template <> |
| 54 struct IntegerForSizeAndSign<8, true> { | 54 struct IntegerForSizeAndSign<8, true> { |
| 55 typedef int64_t type; | 55 typedef int64_t type; |
| 56 }; | 56 }; |
| 57 template <> | 57 template <> |
| 58 struct IntegerForSizeAndSign<8, false> { | 58 struct IntegerForSizeAndSign<8, false> { |
| 59 typedef uint64_t type; | 59 typedef uint64_t type; |
| 60 static_assert(sizeof(uintmax_t) == 8, | |
|
Tom Sepez
2016/11/17 17:04:54
nit: Do you want a <= or >= comparison here? Does
jschuh
2016/11/17 18:06:46
Good question. I can't really test, but I've seen
| |
| 61 "Max integer size not supported for this toolchain."); | |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 // WARNING: We have no IntegerForSizeAndSign<16, *>. If we ever add one to | 64 // WARNING: We have no IntegerForSizeAndSign<16, *>. If we ever add one to |
| 63 // support 128-bit math, then the ArithmeticPromotion template below will need | 65 // support 128-bit math, then the ArithmeticPromotion template below will need |
| 64 // to be updated (or more likely replaced with a decltype expression). | 66 // to be updated (or more likely replaced with a decltype expression). |
| 65 | 67 |
| 66 template <typename Integer> | 68 template <typename Integer> |
| 67 struct UnsignedIntegerForSize { | 69 struct UnsignedIntegerForSize { |
| 68 typedef typename std::enable_if< | 70 typedef typename std::enable_if< |
| 69 std::numeric_limits<Integer>::is_integer, | 71 std::numeric_limits<Integer>::is_integer, |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 : value_(static_cast<T>(rhs.value())) {} | 752 : value_(static_cast<T>(rhs.value())) {} |
| 751 | 753 |
| 752 bool is_valid() const { return std::isfinite(value_); } | 754 bool is_valid() const { return std::isfinite(value_); } |
| 753 T value() const { return value_; } | 755 T value() const { return value_; } |
| 754 }; | 756 }; |
| 755 | 757 |
| 756 } // namespace internal | 758 } // namespace internal |
| 757 } // namespace base | 759 } // namespace base |
| 758 | 760 |
| 759 #endif // BASE_NUMERICS_SAFE_MATH_IMPL_H_ | 761 #endif // BASE_NUMERICS_SAFE_MATH_IMPL_H_ |
| OLD | NEW |