Skip to content

Commit

Permalink
fix: Merge two Math.max()<Math.min() entries #230 (#231)
Browse files Browse the repository at this point in the history
* Merge two `Math.max()<Math.min()` entries #230

* chore: fix formatting

Co-authored-by: Denys Dovhan <[email protected]>
  • Loading branch information
bence98 and denysdovhan authored Apr 26, 2022
1 parent 2be9310 commit 070ed39
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Currently, there are these translations of **wtfjs**:
- [Default behavior Array.prototype.sort()](#default-behavior-arrayprototypesort)
- [resolve() won't return Promise instance](#resolve-wont-return-promise-instance)
- [`{}{}` is undefined](#-is-undefined)
- [`min` is greater than `max`](#min-is-greater-than-max)
- [`arguments` binding](#arguments-binding)
- [An `alert` from hell](#an-alert-from-hell)
- [An infinite timeout](#an-infinite-timeout)
Expand Down Expand Up @@ -1723,17 +1722,32 @@ See for reference `NOTE 2` on the ECMA-262 definition for `toFixed`.

## `Math.max()` less than `Math.min()`

I find this example hilarious:

```js
Math.min(1, 4, 7, 2); // -> 1
Math.max(1, 4, 7, 2); // -> 7
Math.min(); // -> Infinity
Math.max(); // -> -Infinity
Math.min() > Math.max(); // -> true
Math.min() < Math.max(); // -> false
```

### πŸ’‘ Explanation:

- [Why is Math.max() less than Math.min()?](https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min) by Charlie Harvey
This is a simple one. Let's consider each part of this expression separately:

```js
Math.min(); // -> Infinity
Math.max(); // -> -Infinity
Infinity > -Infinity; // -> true
```

Why so? Well, `Math.max()` is not the same thing as `Number.MAX_VALUE`. It does not return the largest possible number.

`Math.max` takes arguments, tries to convert the to numbers, compares each one and then returns the largest remaining. If no arguments are given, the result is βˆ’βˆž. If any value is `NaN`, the result is `NaN`.

The opposite is happening for `Math.min`. `Math.min` returns ∞, if no arguments are given.

- [**15.8.2.11** Math.max](https://262.ecma-international.org/5.1/#sec-15.8.2.11)
- [**15.8.2.11** Math.min](https://262.ecma-international.org/5.1/#sec-15.8.2.12)
- [Why is `Math.max()` less than `Math.min()`?](https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min) by Charlie Harvey

## Comparing `null` to `0`

Expand Down Expand Up @@ -1906,35 +1920,6 @@ if (true) {

Surprisingly, it behaviors the same! You can guess here that `{foo: 'bar'}{}` is a block.

## `min` is greater than `max`

I find this example hilarious:

```js
Math.min() > Math.max(); // -> true
Math.min() < Math.max(); // -> false
```

### πŸ’‘ Explanation:

This is a simple one. Let's consider each part of this expression separately:

```js
Math.min(); // -> Infinity
Math.max(); // -> -Infinity
Infinity > -Infinity; // -> true
```

Why so? Well, `Math.max()` is not the same thing as `Number.MAX_VALUE`. It does not return the largest possible number.

`Math.max` takes arguments, tries to convert the to numbers, compares each one and then returns the largest remaining. If no arguments are given, the result is βˆ’βˆž. If any value is `NaN`, the result is `NaN`.

The opposite is happening for `Math.min`. `Math.min` returns ∞, if no arguments are given.

- [**15.8.2.11** Math.max](https://262.ecma-international.org/5.1/#sec-15.8.2.11)
- [**15.8.2.11** Math.min](https://262.ecma-international.org/5.1/#sec-15.8.2.12)
- [Why is `Math.max()` less than `Math.min()`?](https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min)

## `arguments` binding

Consider this function:
Expand Down

0 comments on commit 070ed39

Please sign in to comment.