Commit 869dd9b3 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[utils] Make Abs return an unsigned value

In most cases, this does not matter, especially if assigning to the
source variable again:
x = Abs(x)

But there are cases where it matters, e.g. when being used as argument
to a template function:
DCHECK_EQ(x, Abs(x));
which would currently *not* fail for x==kMinInt.

R=tebbi@chromium.org

Change-Id: Ia5abfe164db602b80a34548e0bf9b22033b77c6e
Reviewed-on: https://chromium-review.googlesource.com/568028Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46586}
parent 0a4ad440
......@@ -218,12 +218,12 @@ T JSMin(T x, T y) {
}
// Returns the absolute value of its argument.
template <typename T>
T Abs(T a) {
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value>::type>
typename std::make_unsigned<T>::type Abs(T a) {
return a < 0 ? -a : a;
}
// Floor(-0.0) == 0.0
inline double Floor(double x) {
#if V8_CC_MSVC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment