Re: Change FPU round mode



On Nov 02, 2009 05:34, steve wrote:
On Nov 1, 7:20 pm, Yipkei Kwok <yipkeik...@xxxxxxxxx> wrote:
The default x87 FPU rounding mode is `round to the nearest'.

Is there any Fortran command that I can use to change the rounding
mode to `round to 0'?

Not with gfortran. gfortran doesn't support the IEEE 754 intrinsic
module, yet.

I want to add for completeness: If you only want to round the I/O
(writing, output),* GCC 4.5 supports the ROUND= keyword and the R* edit
descriptors of Fortran 2003. This does not help, however with doing the
calculations with the desired rounding.

But if such a command is not available, I know how to change the
rounding mode using assembly instructions. Is there any way to inline
assembly code in Fortran code with the gfortran compiler?
Newer versions of gfortran support the ISO C binding facility. You
could bind to the fenv functions to toggle the rounding mode.

I think gfortran does not touch the rounding thus doing it by calling
fesetround - either directly or by calling a C program which does this
call (or using assembler) should works.

I suspect that libgfortran assumes round-to-nearest.

I think libgfortran does not assume any specific rounding and should
work in principle correctly independing of the rounding. Though there
might be bugs, due to the implicit assumption of one way of rounding.

Tobias

* I wonder how many compilers support rounding on reading/input, e.g.
for reading "0.1" leading to a binary FP number being >0.1 or <0.1.
.