Skip to content
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

Needs an example of what the "precise" means #17

Open
shgysk8zer0 opened this issue May 12, 2024 · 2 comments
Open

Needs an example of what the "precise" means #17

shgysk8zer0 opened this issue May 12, 2024 · 2 comments

Comments

@shgysk8zer0
Copy link

I've looked at the polyfill, but I'm not exactly clear on why or how the algorithm is any more precise. 0.1 + 0.2 !== 0.3 still, and while I kinda get that maybe this isn't meant to fix floating point issues like that, I still don't get how this is meant to be any more "precise" than any basic approach. And just a single example of how this would be any more accurate than a staright-forward nums.reduce() highlighting where and how the simple approach is less accurate/precise than this would really do a lot to clarify why the more expensive operations are warranted.

Also worth mentioning that, due to the lack of such examples, many others are confused by this as well. It's not uncommon for devs to assume that this proposal is meant to resolve floating point arithmetic problems, and I don't think it actually resolves the issues many think it does. Again, just giving a quick example or two of where this is and isn't better than the simple approach would go a very long way.

@bakkot
Copy link
Collaborator

bakkot commented May 12, 2024

There's an example early in the readme:

let values = [1e20, 0.1, -1e20];

values.reduce((a, b) => a + b, 0); // 0

Math.sumPrecise(values); // 0.1

Is that not what you were looking for?

@shgysk8zer0
Copy link
Author

@bakkot My bad. I see that now.

So let's take my issue here as that difference needing more highlighting, including calling out what it does and does not resolve. I'm not sure if I just glossed over the proposal section because that's typically just where I look for the introduction of the new method rather than such details, or because I had previously seen some prior version where I think this was just Math.sum(...nums) .

Shall we just say that the actual problem this proposal is meant to address should be more explicitly detailed, especially with the emphasis implied by using sumPrecise rather than sum ?

Regardless, the core concept of this issue remains in that it should be more clear and detailed on what it is vs what it is not. This may be considered a duplicate of #14, in fact, but that only shows that the confusion isn't uncommon, and I think that giving a few clear examples of what this is and is not is still worth requesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants