cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Portability of truncation of cast: (int)
Portability of truncation of cast: (int)myFloat
Dec 12, 2012 at 6:04am UTC
caibbor
(46)
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?
Dec 12, 2012 at 6:54am UTC
Branflakes91093
(207)
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
Dec 12, 2012 at 7:02am UTC
Topic archived. No new replies allowed.