c++ - Truncate and casting to int of ceiled double -


when performing std::ceil on double value value round whole number. 3.3 become 4.0. can casted or truncated int. 'chop off' part after comma. so:

int foo = (int)std::ceil(3.3); 

so @ first glance store 4 in foo. however, double floating point value. might either 4.000000001 or 3.999999999. latter truncated 3.

but in practice i've never seen behaviour occurring. can safely assume implementation return 4? or ieee-754 this. or have been lucky?

rounding (or ceil-ing) double always, always, exact.

for floating point numbers below 2^(m+1), m number of mantissal bits, integers have exact representations, result can represented.

for floating point numbers above 2^(m+1)... they're integers. makes sense, if think it: there aren't enough mantissal bits stretch down right of decimal point. again rounding/ceil-ing exact.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -