Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: base/numerics/safe_math_impl.h

Issue 596103002: Fix more disabled MSVC warnings, base/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/numerics/safe_math.h ('k') | base/process/kill_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 SAFE_MATH_IMPL_H_ 5 #ifndef SAFE_MATH_IMPL_H_
6 #define SAFE_MATH_IMPL_H_ 6 #define SAFE_MATH_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 -static_cast<typename SignedIntegerForSize<T>::type>(value)); 270 -static_cast<typename SignedIntegerForSize<T>::type>(value));
271 } 271 }
272 272
273 template <typename T> 273 template <typename T>
274 typename enable_if< 274 typename enable_if<
275 std::numeric_limits<T>::is_integer&& std::numeric_limits<T>::is_signed, 275 std::numeric_limits<T>::is_integer&& std::numeric_limits<T>::is_signed,
276 T>::type 276 T>::type
277 CheckedAbs(T value, RangeConstraint* validity) { 277 CheckedAbs(T value, RangeConstraint* validity) {
278 *validity = 278 *validity =
279 value != std::numeric_limits<T>::min() ? RANGE_VALID : RANGE_OVERFLOW; 279 value != std::numeric_limits<T>::min() ? RANGE_VALID : RANGE_OVERFLOW;
280 return std::abs(value); 280 return static_cast<T>(std::abs(value));
281 } 281 }
282 282
283 template <typename T> 283 template <typename T>
284 typename enable_if< 284 typename enable_if<
285 std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed, 285 std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed,
286 T>::type 286 T>::type
287 CheckedAbs(T value, RangeConstraint* validity) { 287 CheckedAbs(T value, RangeConstraint* validity) {
288 // Absolute value of a positive is just its identiy. 288 // Absolute value of a positive is just its identiy.
289 *validity = RANGE_VALID; 289 *validity = RANGE_VALID;
290 return value; 290 return value;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 RangeConstraint validity_; 352 RangeConstraint validity_;
353 353
354 public: 354 public:
355 template <typename Src, NumericRepresentation type> 355 template <typename Src, NumericRepresentation type>
356 friend class CheckedNumericState; 356 friend class CheckedNumericState;
357 357
358 CheckedNumericState() : value_(0), validity_(RANGE_VALID) {} 358 CheckedNumericState() : value_(0), validity_(RANGE_VALID) {}
359 359
360 template <typename Src> 360 template <typename Src>
361 CheckedNumericState(Src value, RangeConstraint validity) 361 CheckedNumericState(Src value, RangeConstraint validity)
362 : value_(value), 362 : value_(static_cast<T>(value)),
363 validity_(GetRangeConstraint(validity | 363 validity_(GetRangeConstraint(validity |
364 DstRangeRelationToSrcRange<T>(value))) { 364 DstRangeRelationToSrcRange<T>(value))) {
365 COMPILE_ASSERT(std::numeric_limits<Src>::is_specialized, 365 COMPILE_ASSERT(std::numeric_limits<Src>::is_specialized,
366 argument_must_be_numeric); 366 argument_must_be_numeric);
367 } 367 }
368 368
369 // Copy constructor. 369 // Copy constructor.
370 template <typename Src> 370 template <typename Src>
371 CheckedNumericState(const CheckedNumericState<Src>& rhs) 371 CheckedNumericState(const CheckedNumericState<Src>& rhs)
372 : value_(static_cast<T>(rhs.value())), 372 : value_(static_cast<T>(rhs.value())),
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 sizeof(T) >= (2 * sizeof(Lhs)) && 493 sizeof(T) >= (2 * sizeof(Lhs)) &&
494 StaticDstRangeRelationToSrcRange<T, Rhs>::value != 494 StaticDstRangeRelationToSrcRange<T, Rhs>::value !=
495 NUMERIC_RANGE_CONTAINED && 495 NUMERIC_RANGE_CONTAINED &&
496 sizeof(T) >= (2 * sizeof(Rhs)); 496 sizeof(T) >= (2 * sizeof(Rhs));
497 }; 497 };
498 498
499 } // namespace internal 499 } // namespace internal
500 } // namespace base 500 } // namespace base
501 501
502 #endif // SAFE_MATH_IMPL_H_ 502 #endif // SAFE_MATH_IMPL_H_
OLDNEW
« no previous file with comments | « base/numerics/safe_math.h ('k') | base/process/kill_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698