Additional Math functions

Jason Orendorff jason.orendorff at
Tue Oct 6 18:03:00 UTC 2015

On Fri, Oct 2, 2015 at 6:37 PM, Alexander Jones <alex at> wrote:
> What do other languages do?

Well, Python's standard library has both a `sum()` builtin and a
statistics module. They handle floating-point weirdness differently:

    >>> sum([1.0, 1e18, -1e18])
    >>> import statistics
    >>> statistics.mean([1.0, 1e18, -1e18])

See <> for statistics module
rationale. I didn't find a PEP for sum().

...But for JS, the question is: why should we think TC39 and JS
engines will be as good at satisfying this need as third-party

I hope that users who require numerical accuracy can just crack open a
book. They should have, in JS, all the floating-point-munging tools
they need to implement a book algorithm. If they don't, let's focus on
providing those!

*Maybe* JS engine implementors can provide as-good accuracy with
better speed. But not necessarily. A standard Math.sum() may even be
slower, because TC39 is likely to specify nice, consistent, but
inconvenient behavior, such as supporting the iterator protocol or
specially handling array holes or infinities or NaN or -0. Library
authors don't have to care about this stuff. TC39 absolutely has to
care---about the risks of underspecification, at least---even at the
expense of speed.


More information about the es-discuss mailing list