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

rounding up vs. rounding down #1

Closed
benibela opened this issue Jun 1, 2021 · 3 comments
Closed

rounding up vs. rounding down #1

benibela opened this issue Jun 1, 2021 · 3 comments

Comments

@benibela
Copy link

benibela commented Jun 1, 2021

I have run these tests on someone's double parser which discovered thousands of wrongly parsed numbers

But on closer examination, that parser still finds the nearest double number. Just there are two nearest numbers.
E.g. 9008309105029287 has 9008309105029288 (+1) and 9008309105029286 (-1)

Is it really important to return the larger one?

@nigeltao
Copy link
Owner

nigeltao commented Jun 4, 2021

If there's a tie then we use standard IEEE 754 round-to-even rules.

https://nigeltao.github.io/blog/2020/eisel-lemire.html#round-to-even has some examples.

At least, that's what I remember doing. Let me know if there's still a discrepancy.

@nigeltao
Copy link
Owner

nigeltao commented Jun 4, 2021

Is it really important to return the larger one?

It is important that parsing text-based formats to float64 values is deterministic, across different libraries. As a silly example, it wouldn't work if a message like "send Bob 3.5 million dollars" was rounded by Bob to 4 million but rounded by me to 3 million, even though both are equally distant.

@benibela
Copy link
Author

If there's a tie then we use standard IEEE 754 round-to-even rules.

But floats with positive exponent are always even. Either direction would be round-to-even

https://nigeltao.github.io/blog/2020/eisel-lemire.html#round-to-even has some examples.

Guess that explains it. Some numbers are more even than even

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