I have problem with interpretation of C standard, the latest draft taken from http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2454.pdf.
Standard evaluation
The standard defines pragma STD FENV_ACCESS
and states (7.6.1p2):
The FENV_ACCESS pragma provides a means to inform the implementation when a program might
access the floating-point environment to test floating-point status flags or run under non-default
floating-point control modes.
It is not clear why this pragma in necessary to run under non-default floating-point control modes. Is it because
- setting these non-default modes require write to control mode register, or
- the pragma is necessary always even if non-default current mode is already set?
Later in this paragraph of the standard we find:
If part of a program tests floating-point status flags or establishes non-default floating-point
mode settings using any means other than the FENV_ROUND pragmas, but was translated with the
state for the FENV_ACCESS pragma "off", the behavior is undefined.
It looks like testing current mode without changing it is not an undefined behavior. But the footnote in the same paragraph states:
In general, if the state of FENV_ACCESS is "off", the translator can assume that the flags are
not tested, and that default modes are in effect, except where specified otherwise by an
FENV_ROUND pragma.
The question
So if no pragma FENV_ACCESS was specified, does it mean default rounding mode is in effect?
Let's suppose that pragma FENV_ROUND is absent as well, and compiler assumes FENV_ACCESS is off by default, it is necessary for backward compatibility.
Example
Consider the following source code:
#include <math.h>
float func_01(float x) {
return nearbyint(x);
}
The function nearbyint
is described (7.12.9.3) as making rounding using current rounding mode. But the code does not have pragma FENV_ACCESS
. Does it mean that current rounding mode may be ignored and nearbyint
is same as roundeven
?