Details

Bug

Status: Closed

Major

Resolution: Fixed

2.0

None
Description
It appears that $math.max has had a bug since at least 2.0, or at least I'm at a loss as to why the observed behavior would be expected, and it doesn't appear to be documented.
$math.max(0,0)
returns
4.9E324
that is, Double.MIN_VALUE.
It's easy to see why in the source. Using 3.0 here, we see:
public Number max(Object... nums) { double value = Double.MIN_VALUE; Number[] ns = new Number[nums.length]; for (int i=0; i<nums.length; i++) { Number n = toNumber(nums[i]); if (n == null) { return null; } value = Math.max(value, n.doubleValue()); ns[i] = n; } return matchType(value, ns); }
So rather than delegating to Java.lang.Math.max directly, each iter takes the Math.max of the current value and Double.MIN_VALUE. Ergo, if the arguments are 0, that's always < Double.MIN_VALUE, so the result is in turn Double.MIN_VALUE.
The same goes for $math.max(0) (just one arg) but at least that could be considered a usage error.