In message <fg**************************@news.fu-berlin.de>
Francois Grieu <fg****@micronet.fr> wrote:
Does ISO C insure this program's output is 0 ?
#include <fenv.h>
#include <math.h>
int main(void)
{
You need to put
#pragma STDC FENV_ACCESS ON
either here or before main, otherwise you're not allowed to change the
rounding mode.
#ifdef FE_TOWARDZERO
unsigned long a;
double d;
int j;
fesetround(FE_TOWARDZERO);
a = 0xFFFFFFFF;
d = 0;
for(j=10;--j;)
d = (d+a)*((double)1/65536/65536);
do
if ((unsigned long)floor(d*a)==a)
return 1;
while (--a);
#endif
return 0;
}
Looks like it's got to return 0 to me, yes.
As an aside, my <fenv.h> defines FE_TOWARDZERO as an enum,
isn't that a defect (assuming FE_TOWARDZERO is supported)?
FE_TOWARDZERO has to exist as a macro if the rounding mode is supported, so
that it can be tested for with #ifdef. The macro could expand to an enum
value though:
enum { FE_TONEAREST, FE_TOWARDZERO };
#define FE_TOWARDZERO FE_TOWARDZERO
--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW:
http://www.tematic.com/