Closed vermuz closed 3 years ago
Great! Could you send a PR with a corresponding section?
I have to disagree: it may look funny but it is very natural behavior and not JavaScript-specific. Actually, one would expect Math.min()
and Math.max()
to be undefined
because an empty set does not contain any elements, hence a maximum or minimum cannot exist. But that wouldn't really have any advantage and would be quite inconvenient because properties like
Math.max(...A) <= Math.max(...A.concat(B))
andMath.max(Math.max(...A), Math.max(...B)) === Math.max(...A.concat(B))
would not necessarily be true for empty sets. In that sense, Math.max/min()
being +/-Infinity
is the only choice that preserves these and other properties.
Mathematically, Math.max
and Math.min
behave like the supremum and infimum. The supremum of a set of numbers A is the smallest number that is greater than all elements of A. The supremum is called maximum of A if the supremum of A is in A. So for a finite nonempty set of numbers, supremum and maximum are one and the same. The supremum of the empty set is negative infinity because all numbers are upper bounds for the empty set and the smallest of these is negative infinity.
Although, i agree about the inherent mathematical logic, as javascript user who probably hasnt thought through the logic, this behavior is pretty funny.
console.log(Math.min(1,4,7,2));
1
console.log(Math.max(1,4,7,2));
7
console.log(Math.min());
Infinity
console.log(Math.max());
-Infinity
i find this hilarious,
console.log(Math.min() > Math.max());
true
:tada: This issue has been resolved in version 1.17.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Thought, it should be here as well, https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min