Adding support for long values in MathUtils.clamp()

BUG=None

Review URL: https://codereview.chromium.org/295283003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272996 0039d316-1c4b-4281-b951-d872f2087c98
parent b6d17247
......@@ -29,6 +29,24 @@ public class MathUtils {
return value;
}
/**
* Returns the passed in value if it resides within the specified range (inclusive). If not,
* it will return the closest boundary from the range. The ordering of the boundary values does
* not matter.
*
* @param value The value to be compared against the range.
* @param a First boundary range value.
* @param b Second boundary range value.
* @return The passed in value if it is within the range, otherwise the closest boundary value.
*/
public static long clamp(long value, long a, long b) {
long min = (a > b) ? b : a;
long max = (a > b) ? a : b;
if (value < min) value = min;
else if (value > max) value = max;
return value;
}
/**
* Returns the passed in value if it resides within the specified range (inclusive). If not,
* it will return the closest boundary from the range. The ordering of the boundary values does
......@@ -46,4 +64,4 @@ public class MathUtils {
else if (value > max) value = max;
return value;
}
}
\ No newline at end of file
}
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