| 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_CONVERSIONS_IMPL_H_ | 5 #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
| 6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ | 6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 static constexpr Dst max() { | 151 static constexpr Dst max() { |
| 152 // We use UINTMAX_C below to avoid compiler warnings about shifting floating | 152 // We use UINTMAX_C below to avoid compiler warnings about shifting floating |
| 153 // points. Since it's a compile time calculation, it shouldn't have any | 153 // points. Since it's a compile time calculation, it shouldn't have any |
| 154 // performance impact. | 154 // performance impact. |
| 155 return DstLimits::max() - static_cast<Dst>((UINTMAX_C(1) << shift) - 1); | 155 return DstLimits::max() - static_cast<Dst>((UINTMAX_C(1) << shift) - 1); |
| 156 } | 156 } |
| 157 | 157 |
| 158 static constexpr Dst min() { | 158 static constexpr Dst min() { |
| 159 return std::numeric_limits<Dst>::is_iec559 ? -DstLimits::max() | 159 return std::numeric_limits<Dst>::is_iec559 ? -DstLimits::max() |
| 160 : DstLimits::min(); | 160 : DstLimits::min(); |
| 161 } | 161 }; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 template < | 164 template < |
| 165 typename Dst, | 165 typename Dst, |
| 166 typename Src, | 166 typename Src, |
| 167 IntegerRepresentation DstSign = std::numeric_limits<Dst>::is_signed | 167 IntegerRepresentation DstSign = std::numeric_limits<Dst>::is_signed |
| 168 ? INTEGER_REPRESENTATION_SIGNED | 168 ? INTEGER_REPRESENTATION_SIGNED |
| 169 : INTEGER_REPRESENTATION_UNSIGNED, | 169 : INTEGER_REPRESENTATION_UNSIGNED, |
| 170 IntegerRepresentation SrcSign = std::numeric_limits<Src>::is_signed | 170 IntegerRepresentation SrcSign = std::numeric_limits<Src>::is_signed |
| 171 ? INTEGER_REPRESENTATION_SIGNED | 171 ? INTEGER_REPRESENTATION_SIGNED |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 "Argument must be numeric."); | 256 "Argument must be numeric."); |
| 257 static_assert(std::numeric_limits<Dst>::is_specialized, | 257 static_assert(std::numeric_limits<Dst>::is_specialized, |
| 258 "Result must be numeric."); | 258 "Result must be numeric."); |
| 259 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); | 259 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace internal | 262 } // namespace internal |
| 263 } // namespace base | 263 } // namespace base |
| 264 | 264 |
| 265 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ | 265 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
| OLD | NEW |