Re: Conflicts between C standard and 754-2008
On Jan 1 2011, Michel Hack wrote:
Unless I couldn't figure out how to use fesetround(FE_TOWARDZERO),
Without assuming anything about your C competence, you are aware that
FENV_ACCESS must be 'on' over BOTH the '#include <stdlib.h>' AND the
use of strtod(), aren't you? As well as <fenv.h> and fesetround(),
of course. I doubt that gcc takes note of that, but it's not impossible.
You may also need some arcane compiler options because, quite rightly,
the default is not C99 with Annex F support. That's probably irrelevant,
too, but needs mentioning. And, of course, things may be different in a
later version, either of gcc or glib.
it
appears that Linux (with gcc version 4.3.2) strtod() does not honour
the rounding direction at all:
<175: 74 => ./td 0.1 1
rc from fesetround(rm): 0 rm=3072
td: 3FB99999 9999999A 3 status=0000 0.1
<175: 82 => uname -r -m
2.6.27.19-5-default x86_64
(The same program under AIX returns ...999 for TOWARDZERO
and ...99A for NEAREST, as expected. It does however return
Infinity for overflow regardless of rounding mode, guided by
the not-yet-revised C standard.)
As the revision changes the requirement for delivering HUGE_VAL
regardless into undefined behaviour if a non-default rounding
is in effect, there is no reason for an incompatible change.
Regards,
Nick Maclaren.