-
Notifications
You must be signed in to change notification settings - Fork 3
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
sumPrecise name and "floating point" language may be misleading #14
Comments
Yeah, we were aware that there would be this confusion. But the name does need to somehow indicate that this is more precise than normal floating point summation, and I think any name with that property would confuse people as it did you. So I don't see a way to avoid this problem. At some point people will have to learn how floating point numbers actually work. For what it's worth, this does perform precise floating point math. The problem here is that writing That doesn't generalize to adding more than 2 numbers normally - |
Understood, the naming does pose a dilemma. I wonder if there would be any other naming options which could describe properties of this solution in an alternative way 🤔 Anyway, short of finding another suitable name, happy to either leave this open for visibility to others or close it - whatever fits wishes of the project. |
It was originally called No one made any other suggestions. I half-suggested |
Reading through a bit of Shewchuk's paper and researching about related material, 2 additional suggestions came to mind:
|
Neither of those really suggest "this is more precise than naive summation". |
May I suggest:
Something with -er postfix suggests its better precision but not exact precision. |
Rather than treating the problem of user confusion that I like
@Event-Horizon's suggestion of an -er postfix could be good and would still be a valid name after proposal-decimal lands. I also support keeping the name |
This method will never accept Decimals (for the same reason it doesn't accept BigInts), so I don't think the possible addition of a Decimal type to the language has much bearing here. |
Ok. Sorry for my confusion. Nevertheless I think we should not worry too much about picking a method name in order to educate users on floating point in JS generally. Rather we should pick one that describes the method well, which |
Sorry if this is an ignorant question - Does this method's name need to express the fact that it's doing more precise summation? The current README says:
How much slower is this precise approach? At what point would I not want to reach for it? Unless this method is much slower and likely to be a footgun, would it be better to just call it (Asking because I worry about the same confusion with the "precise" wording) If the risk of performance footgun is high, I'd vote for |
Optimistically for lists of > 100 elements it will be perhaps 4x slower than naive summation implemented natively would be, but that's just from eyeballing graphs from this post. As a user it will still probably be faster than your own code, at least until your code gets into a higher optimization tier in the engine. Though to be clear, these are at this point just my personal guesses; it's hard to know this sort of thing prior to actual implementations. Whether that slowdown matters depends on your perspective, I suppose. Engines expressed reservations about using the name "sum" for anything more complicated than naive summation.
|
Just want to echo the thought that IEEE standard requires that all However, if that's not on the table, Of the former two, |
Generally agree on the "correct" option just being If not that naming though, I think the ambiguity in the I think that's actually desirable since the "strictness" has some performance tradeoffs and a fairly nuanced meaning beyond what you'd assume from "precise". I don't think a short name can clearly convey the nuance of what this proposal aims to do, so a less clear short name is actually a bit better (again if the plain |
@RyanKadri the semantics are simply: "the result is completely correct to the available precision". Which I'd argue is exactly what you would expect from Far more nuanced would be the semantics of a naive summation's output: "the result may be correct, or completely wrong, depending on a myriad of edge-cases". ( |
This might be a dumb question, I'm not terribly familiar with this space: We already have I might be seeing similarity where there is none though: My understanding of the spec, and also reading the paper is that the implementation can rely on the same mechanism (IEEE's If it does have a relationship to those methods, I think we might want to consider some other questions. what happens if we need f16 sums? What happens if other methods are added later? Should we have aliasing now? |
"Math.fround" means "round to the nearest JS number which is precisely representable as a 32-bit float". Here we're doing maximally precise 64-bit summation. So I think suggesting a similarity between the two would be misleading; I've always assumed that "f" in "fround" stands for the C type So, no, I don't think there's much relationship to |
thanks for the clarification! |
Hi @bakkot, thanks for this proposal!
When I was reading the
Math.sumPrecise
proposal tweet from @robpalme, I somehow read into it that it would perform precise floating point math, to avoid the classic0.1 + 0.2 = 0.30000000000000004
unusual behavior from JavaScript.But running the polyfill in Node.js does not lead to other results:
But this appears to be a separate issue, which @jessealama @apaprocki @jirkamarsik and previously @littledan have worked on in the Decimal proposal:
I wonder if the name
sumPrecise
would confuse other users (as it did me) enough to consider it when looking for solutions for floating point arithmetic problems in JS.The text was updated successfully, but these errors were encountered: