| 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 // Slightly adapted for inclusion in V8. | 5 // Slightly adapted for inclusion in V8. |
| 6 // Copyright 2014 the V8 project authors. All rights reserved. | 6 // Copyright 2014 the V8 project authors. All rights reserved. |
| 7 | 7 |
| 8 #ifndef V8_BASE_SAFE_MATH_IMPL_H_ | 8 #ifndef V8_BASE_SAFE_MATH_IMPL_H_ |
| 9 #define V8_BASE_SAFE_MATH_IMPL_H_ | 9 #define V8_BASE_SAFE_MATH_IMPL_H_ |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 *validity = DstRangeRelationToSrcRange<T>(tmp); | 201 *validity = DstRangeRelationToSrcRange<T>(tmp); |
| 202 return static_cast<T>(tmp); | 202 return static_cast<T>(tmp); |
| 203 } | 203 } |
| 204 | 204 |
| 205 template <typename T> | 205 template <typename T> |
| 206 typename enable_if<std::numeric_limits<T>::is_integer && | 206 typename enable_if<std::numeric_limits<T>::is_integer && |
| 207 std::numeric_limits<T>::is_signed && | 207 std::numeric_limits<T>::is_signed && |
| 208 (sizeof(T) * 2 > sizeof(uintmax_t)), | 208 (sizeof(T) * 2 > sizeof(uintmax_t)), |
| 209 T>::type | 209 T>::type |
| 210 CheckedMul(T x, T y, RangeConstraint* validity) { | 210 CheckedMul(T x, T y, RangeConstraint* validity) { |
| 211 // if either side is zero then the result will be zero. | 211 // If either side is zero then the result will be zero. |
| 212 if (!(x || y)) { | 212 if (!x || !y) { |
| 213 return RANGE_VALID; | 213 return RANGE_VALID; |
| 214 | 214 |
| 215 } else if (x > 0) { | 215 } else if (x > 0) { |
| 216 if (y > 0) | 216 if (y > 0) |
| 217 *validity = | 217 *validity = |
| 218 x <= std::numeric_limits<T>::max() / y ? RANGE_VALID : RANGE_OVERFLOW; | 218 x <= std::numeric_limits<T>::max() / y ? RANGE_VALID : RANGE_OVERFLOW; |
| 219 else | 219 else |
| 220 *validity = y >= std::numeric_limits<T>::min() / x ? RANGE_VALID | 220 *validity = y >= std::numeric_limits<T>::min() / x ? RANGE_VALID |
| 221 : RANGE_UNDERFLOW; | 221 : RANGE_UNDERFLOW; |
| 222 | 222 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 StaticDstRangeRelationToSrcRange<T, Rhs>::value != | 522 StaticDstRangeRelationToSrcRange<T, Rhs>::value != |
| 523 NUMERIC_RANGE_CONTAINED && | 523 NUMERIC_RANGE_CONTAINED && |
| 524 sizeof(T) >= (2 * sizeof(Rhs)); | 524 sizeof(T) >= (2 * sizeof(Rhs)); |
| 525 }; | 525 }; |
| 526 | 526 |
| 527 } // namespace internal | 527 } // namespace internal |
| 528 } // namespace base | 528 } // namespace base |
| 529 } // namespace v8 | 529 } // namespace v8 |
| 530 | 530 |
| 531 #endif // V8_BASE_SAFE_MATH_IMPL_H_ | 531 #endif // V8_BASE_SAFE_MATH_IMPL_H_ |
| OLD | NEW |