tc39 / proposal-math-sum

TC39 proposal to add a summation method to JavaScript
https://tc39.github.io/proposal-math-sum
72 stars 1 forks source link

check argument list length up front #4

Closed michaelficarra closed 3 months ago

michaelficarra commented 5 months ago

I'm guessing this was left over from a version that took an iterator?

Also, do we really need to do this in Math.sum? It seems like if we're going to do this anywhere, we should make it apply everywhere.

bakkot commented 5 months ago

I'm guessing this was left over from a version that took an iterator?

Not a leftover, yes an intentional decision so that the iterable-taking version could work the same way. Since that's observable (unless we get rid of the ToNumber calls) I'm inclined to leave it as-is.

Also, do we really need to do this in Math.sum? It seems like if we're going to do this anywhere, we should make it apply everywhere.

We need to do this in Math.sum because at least a couple of the reasonable algorithms for handling arbitrary-precision arithmetic can overflow if fed more than 2**53 values. That's not true for e.g. Math.max.

I guess we could leave it out and just assume implementations are OK with violating the spec in that case? But it seems better to specify somehow.

michaelficarra commented 5 months ago

I don't think we need to mirror the algorithms that closely. Also, if we're just calling ToNumber for consistency with Math.min/max, I don't think that's great motivation either.

michaelficarra commented 3 months ago

This isn't relevant any longer because the API does take an iterator now.