x86 rounding mode question


Is there a recommended way to round to the nearest whole (x86 RC field of FPU control = 00) ?

It appears an intentional truncation instruction is generated (if ms disassembly is correct):


%1 = fptosi double %0 to i64

00370025 fisttp qword ptr [esp]



Hi Bob,

We don't have great support for this. We support the rounding modes that C uses, but don't have the ability to control the rounding flags in the machine, and don't have a way to tell the optimizer that the program is fiddling with them.


The description of fptosi as "converts...into the nearest (rounding towards zero)" is perhaps a little confusing. That is actually a truncation. No, there's no way to change rounding modes, although people keep talking about adding it. It is not an easy thing to do.