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

Floating point to integer casts rounding wrong #642

Open
LBPHacker opened this issue Apr 11, 2019 · 1 comment
Open

Floating point to integer casts rounding wrong #642

LBPHacker opened this issue Apr 11, 2019 · 1 comment

Comments

@LBPHacker
Copy link
Member

We likely have a lot of code that assumes floating point conversion to integer rounding toward negative infinity, while in fact it rounds toward 0.

#622 (comment)

@moonheart08
Copy link
Contributor

moonheart08 commented Apr 11, 2019

@LBPHacker wait i thought i mentioned this before. I didn't? Oops. Well now it's an issue, so that helps.

The +0.5f trick is slightly faster, so when negative numbers are impossible using it should be fine. Maybe make it into a function, i.e.

int fast_nonneg_toint(float)

or similar, so that the safe usages of it are more obvious.

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