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

Unified Diff: base/numerics/safe_math_impl.h

Issue 2563003003: Revert of Cleanup sign checking in safe math code (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/numerics/safe_conversions_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_math_impl.h
diff --git a/base/numerics/safe_math_impl.h b/base/numerics/safe_math_impl.h
index f648d1642074f9071c66891e9bd2f4e8f7a7afb8..ae0a5b1d4f031d8228ee47172daf27153dd6ce77 100644
--- a/base/numerics/safe_math_impl.h
+++ b/base/numerics/safe_math_impl.h
@@ -47,8 +47,8 @@
template <typename T>
constexpr bool HasSignBit(T x) {
// Cast to unsigned since right shift on signed is undefined.
- return static_cast<typename std::make_signed<T>::type>(x) <
- static_cast<typename std::make_signed<T>::type>(0);
+ return !!(static_cast<typename std::make_unsigned<T>::type>(x) >>
+ PositionOfSignBit<T>::value);
}
// This wrapper undoes the standard integer promotions.
« no previous file with comments | « base/numerics/safe_conversions_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698