Portability of truncation of cast: (int)myFloat

Brandon Captain (18)
I have some functions that depend on the truncation as opposed to rounding when casting a float to an int. is this portable behavior, or bad practice?

Does any c++ implementation round instead of truncate, or is it written in the standard somewhere?
Branflakes91093 (109)
It's in the standard.

An rvalue of a floating point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is discarded.
Last edited on
Registered users can post here. Sign in or register to post.