Floating point problem revisited

From: Eugene Chu <chu_at_musp0.Jpl.Nasa.Gov>
Date: Wed, 10 Jul 1996 02:02:57 -0700

Ages ago, someone either on this list or one of the DEC news groups
mentioned this problem, and I don't remember how it was resolved.
I've run into again on my AlphaStation 250 4/266 running OSF v3.2c.
Basically, it has to do with how a particular expression is displayed
by the printf function in their C program:

#include <stdio.h>

main()

{
float fff = 4.333;
float ggg = 1/65535;

printf("ggg = %f\n",ggg);
printf("1/65535 = %f\n",1/65535);
printf("fff = %f\n",fff);
printf("1/65535 = %f\n",1/65535);
printf("ggg = %f\n",ggg);

}

gives the outputs:

ggg = 0.000000
1/65535 = 0.000000
fff = 4.333000
1/65535 = 4.333000
ggg = 0.000000

while on all other systems I've tested it on (Solaris, Ultrix, IRIX, AIX)
gives the correct result:

ggg = 0.000000
1/65535 = 0.000000
fff = 4.333000
1/65535 = 0.000000
ggg = 0.000000

On the OSF system, DEC C v3.5 was used, but he same outputs are
generated on a system running OSF v1.3a and DEC C v1.0(?); the second
output for 1/65535 picked up the value of fff from the previous line for
some reason. This didn't seem to change regardless of the optimization
flags used.

In playing with this program a little, I found that if the expression
1/65536 was ever assigned to a variable, the correct results will be
obtained, and this anomaly appears to only show up on the printf. But
it's still an anomaly, and certainly not befitting an otherwise
excellent compiler that is known for its strict adherance to standards.

So, does anyone know if DEC has a fix for this?

eyc
Received on Wed Jul 10 1996 - 12:06:39 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT