The x87 FPU implements four rounding methods in hardware. Those are :
- Round to nearest (even)
- Round down, towards negative infinity
- Round up, towards positive infinity
- Round toward zero
The "Round to nearest (even)" method is used by default by the FPU, so there's a high chance you're already using it. The rounding mode is taken into account when the FPU is making calculations, and conversions between different floating-point formats (32, 64, and 80 bits in this case).
The rounding mode is controlled by the x87 Control Word. You can set the new value with the FLDCW
instruction, or get the current value via FSTCW
for verification. For more information about the instructions and the format of the word, please see 8.1.5 of the Intel Basic Architecture manual.
However, please do note that the control word is supposed to be controlled only by operating system software, not by applications themselves. If you choose to change the control word, make sure you restore it before quitting your program.
FRNDINT
is used to round a floating-point value currently on top of the stack to the nearest integral value. With rounding to even, the result of rounding 1.010101101
will be 1. However, if you turn on rounding towards positive infinity, then the result will be 2.