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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 438 |
439 public: | 439 public: |
440 template <typename Src, NumericRepresentation type> | 440 template <typename Src, NumericRepresentation type> |
441 friend class CheckedNumericState; | 441 friend class CheckedNumericState; |
442 | 442 |
443 CheckedNumericState() : value_(0.0) {} | 443 CheckedNumericState() : value_(0.0) {} |
444 | 444 |
445 template <typename Src> | 445 template <typename Src> |
446 CheckedNumericState( | 446 CheckedNumericState( |
447 Src value, | 447 Src value, |
448 RangeConstraint validity, | 448 RangeConstraint /*validity*/, |
449 typename std::enable_if<std::numeric_limits<Src>::is_integer, int>::type = | 449 typename std::enable_if<std::numeric_limits<Src>::is_integer, int>::type = |
450 0) { | 450 0) { |
451 switch (DstRangeRelationToSrcRange<T>(value)) { | 451 switch (DstRangeRelationToSrcRange<T>(value)) { |
452 case RANGE_VALID: | 452 case RANGE_VALID: |
453 value_ = static_cast<T>(value); | 453 value_ = static_cast<T>(value); |
454 break; | 454 break; |
455 | 455 |
456 case RANGE_UNDERFLOW: | 456 case RANGE_UNDERFLOW: |
457 value_ = -std::numeric_limits<T>::infinity(); | 457 value_ = -std::numeric_limits<T>::infinity(); |
458 break; | 458 break; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 sizeof(T) >= (2 * sizeof(Lhs)) && | 523 sizeof(T) >= (2 * sizeof(Lhs)) && |
524 StaticDstRangeRelationToSrcRange<T, Rhs>::value != | 524 StaticDstRangeRelationToSrcRange<T, Rhs>::value != |
525 NUMERIC_RANGE_CONTAINED && | 525 NUMERIC_RANGE_CONTAINED && |
526 sizeof(T) >= (2 * sizeof(Rhs)); | 526 sizeof(T) >= (2 * sizeof(Rhs)); |
527 }; | 527 }; |
528 | 528 |
529 } // namespace internal | 529 } // namespace internal |
530 } // namespace base | 530 } // namespace base |
531 | 531 |
532 #endif // BASE_NUMERICS_SAFE_MATH_IMPL_H_ | 532 #endif // BASE_NUMERICS_SAFE_MATH_IMPL_H_ |
OLD | NEW |