Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is Math.max() less than Math.min()? #23

Closed
vermuz opened this issue Aug 1, 2017 · 4 comments
Closed

Why is Math.max() less than Math.min()? #23

vermuz opened this issue Aug 1, 2017 · 4 comments
Assignees
Labels
new-example A proposal of the new example released Issues and PRs released by semantic-release

Comments

@vermuz
Copy link
Contributor

vermuz commented Aug 1, 2017

Thought, it should be here as well,
https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min

@denysdovhan
Copy link
Owner

Great! Could you send a PR with a corresponding section?

@denysdovhan denysdovhan added the new-example A proposal of the new example label Aug 8, 2017
@ghost
Copy link

ghost commented Aug 8, 2017

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)) and
  • Math.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.

@vermuz
Copy link
Contributor Author

vermuz commented Aug 8, 2017

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

@denysdovhan denysdovhan self-assigned this Feb 5, 2021
github-actions bot pushed a commit that referenced this issue Feb 6, 2021
# [1.17.0](v1.16.0...v1.17.0) (2021-02-06)

### Bug Fixes

* Lint markdown files ([aa26445](aa26445))

### Features

* Add A stringified string example. Close [#113](#113) ([de081e4](de081e4))
* Add alert from hell. Close [#55](#55) ([1d973b9](1d973b9))
* Add an example with arguments. Close [#35](#35) ([1289b0c](1289b0c))
* Add an infinite timeout example. Close [#61](#61) ([f356deb](f356deb))
* Add comparison table. Close [#107](#107) ([c40b0df](c40b0df))
* Add double dot example. Close [#124](#124) ([597b5ee](597b5ee))
* Add example with Math.min and Math.max. Close [#23](#23). ([ad120b2](ad120b2))
* Add Extra Newness. Close [#78](#78) ([81316dc](81316dc))
* Add Split a string by a space. Close [#171](#171) ([827da42](827da42))
* Add Why you should use semicolons. Close [#112](#112) ([7488b34](7488b34))
* Non-strict comparison of a number to true. Close [#135](#135) ([0242818](0242818))
@github-actions
Copy link

github-actions bot commented Feb 6, 2021

🎉 This issue has been resolved in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Issues and PRs released by semantic-release label Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-example A proposal of the new example released Issues and PRs released by semantic-release
Projects
None yet
Development

No branches or pull requests

2 participants