BUG=skia:5967
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4751
Change-Id: Ie846560ebdaf11e1a5247842b3549ade1e100af2
Reviewed-on: https://skia-review.googlesource.com/4751
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
if (0 == range) {
return;
} else {
- if (*n < 0) {
- *n = *n * -1;
- }
- if (*n < 0) {
- // abs(INT_MIN) = INT_MIN, so we check this to avoid accidental negatives.
- *n = min;
- return;
- }
- *n = min + *n % range;
+ if (*n < 0) { // Handle negatives
+ if (*n != std::numeric_limits<T>::lowest()) {
+ *n *= -1;
+ }
+ else {
+ *n = std::numeric_limits<T>::max();
+ }
+ }
+ *n = min + (*n % range);
}
}