nathansmith/javascript-quiz — pull request #13 by bfontaine (2013-01-20 21:43:30+00:00)
Title: Fix sum function answer (again)

The actual function doesn’t work on large values, [e.g.](https://github.com/nathansmith/javascript-quiz/pull/11#issuecomment-12463329):

```js
add( 1e306 ) === Infinity; // true

add( 1e300, 1e300) === 1e300 + 1e300; // false
```

Multiplying a large value with another large value may result in an infinite one (JS doesn’t support numbers > 1e307). So, since the `factor` trick is used only to avoid weird decimal behavior, we have to split each value into an integer part and a decimal one, and multiply only the decimal one by `factor`. Then, we add the integer part and the decimal one divided by `factor`