-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Math.sum
?
#4
Comments
Since we're "pivoting" this proposal to be a broader Math update, I think this addition is solid. |
If |
Here's an attempt at being more specific:
Here's a possible implementation:
|
Actually I think all arguments should be coerced ToNumber, like almost all builtin Math methods. In other words, it should definitely work on strings. |
Effectively, |
TIL that |
Why don't you adopt Kahan summation algorithm? |
That sounds like a specific implementation, which the spec usually does not dictate. That's the sort of thing that if it is not observable, an implementation is free to use. |
@ljharb Kahan summation algorithm is a compensated summation (observable).
Stream API (Collection) in Java use this algorithm. |
@petamoriken Python has Maybe add both? 😄 |
I vote for single accurate |
That's going to be a different proposal |
I agree with @ljharb, the algorithm should be implementation-defined. The only requirement the spec should impose, is to make the sum as accurate/precise as possible (by minimizing rounding-errors). This can be accomplished with summation-algorithms designed for F.P.-arithmetic, or by internally using |
To be clear; the spec will need to include some algorithm. It’s just that it should be possible for implementations to choose another one that’s observably the same. |
Simplifying things like
Math.sum(...Object.values(x))
orMath.sum(...numbers)
where previously we'd need.reduce((a, b) => a+ b)
?The text was updated successfully, but these errors were encountered: