The rounding comes from the IEEE-754 floating type standard which is used by many systems. The reason is that you can represent numbers only for a finit precision. And one of the floating point represantation is standardized by the IEEE-754.
If you want to truncate the number after some specific digits, then you can use the std::trunc
function which you can find in the math
respectively cmath
header file.
If you only want to truncate it on the output streams then you can use the setprecision
directive using the #include<iomanip>
header file.
For tweaking the rounding operations you are able to set some compiler flags. An example for gcc
would be the fast-math compiler flag. (for more information look here gcc floating point compiler flags)
EDIT
According to my comment here you will find further information for transforming floating types to non-floating-types and then to two's complement.
So for further information look here:
truncating floats
convert to two's complement and further information for rounding-error evaluation
What you could also try is to load your floats to the SSE,AVX, ... (depends on your system)
.