andrewplummer/Sugar — pull request #395 by Zegnat (2013-11-19 16:28:57+00:00)
Title: Parity for non-integers.

1. All non-integers are odd in Sugar. This is wrong as parity is only defined for integers.

``` js
(1.1).isEven(); // => false
(1.1).isOdd(); // => true, expected false
```

2. ±`Infinity` is also odd in Sugar.

``` js
Infinity.isEven(); // => false
Infinity.isOdd(); // => true
```

The Mathematics Stack Exchange tries to answer the question of whether [infinity is an odd or even number](http://math.stackexchange.com/questions/49034/is-infinity-an-odd-or-even-number). [One such answer](http://math.stackexchange.com/a/49046) is that the “smallest infinity ω is even, ω + 1 is odd,” etc. But I believe this goes too far for what JavaScript is expected to handle.

In JavaScript `1 + Infinity === Infinity`, according to [atleast one answer on SE](http://math.stackexchange.com/a/49039) “this may yield an obstruction to extending parity arithmetic”. In other words, parity cannot be defined. That’s also what I think should be happening in Sugar.

Either way, Sugar is declaring `Infinity` to be odd, which is wrong in both cases.

This proposed fix returns `false` for all non-integer numbers: `NaN`, `Infinity`, and those with a decimal component.