-
Enhancement
-
Resolution: Future Project
-
P4
-
None
-
9, 10, 11
A DESCRIPTION OF THE REQUEST :
Some operations in Math util class are commutative and associative, but only allow 2 parameters where one can expect those operations to work with any number of parameters.
To make it easier to use those, it'd be useful to provide some varargs implementations of operations which are commutative and associative. Typical ones I have read use-case for today are Math.min(...) and Math.max(...) but it could extend to addExact(...) or multiplyExact(...) and maybe others.
JUSTIFICATION :
It would make it much easier to implement some comparisons between several collections/arrays.
---------- BEGIN SOURCE ----------
int a = 0,
int b = 1;
int c = 0;
assertEquals(1, Math.max(a, b, c));
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround consists in chaining invocations of such operations.
Some operations in Math util class are commutative and associative, but only allow 2 parameters where one can expect those operations to work with any number of parameters.
To make it easier to use those, it'd be useful to provide some varargs implementations of operations which are commutative and associative. Typical ones I have read use-case for today are Math.min(...) and Math.max(...) but it could extend to addExact(...) or multiplyExact(...) and maybe others.
JUSTIFICATION :
It would make it much easier to implement some comparisons between several collections/arrays.
---------- BEGIN SOURCE ----------
int a = 0,
int b = 1;
int c = 0;
assertEquals(1, Math.max(a, b, c));
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround consists in chaining invocations of such operations.
- duplicates
-
JDK-8276197 Update Math.max(...) and Math.min(...) to support variable parameters
-
- Closed
-