Is this proper way to round a floating point value to an integer? #2776
Replies: 1 comment 1 reply
-
What do you mean with incorrect behavior and safe? There are integer values that are representable in I do not understand what problem your code solves. I would do just casting from
It generates the only |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My concern is that the
round
function still returns a floating point value, so if the value can not be represented as a whole integer, then casting to integer will truncate the decimal part which leads to incorrect behavior (?). this compiles tovroundps
andvcvttps2dq
.so im not sure if it's safe or not? the other way would be
This is at least safe but a little slower. I would love to know if round function does the job or I need to implement my own rounding function like this.
Beta Was this translation helpful? Give feedback.
All reactions