floating point constants
fieland at hobbiton.prime.com
fieland at hobbiton.prime.com
Fri Jul 28 01:08:00 AEST 1989
According to K. & R., if the second operand of the division operator
is zero, the result is undefined. Therefore, the compiler is free
to do what it wants with this.
On a more practical note, the following program will cause the sun 386i
cc compiler to print out Inf, -Inf, and -Nan: (sic)
/* This should print out
inf
-inf
NaN
*/
main()
{float f1, f2, f3, f4 = 0;
f1 = 1.0/f4;
f2 = -1.0/f4;
f3 = 0.0/f4;
printf("%f\n",f1);
printf("%f\n", f2);
printf("%f\n", f3);
}
Peggy Fieland
fieland at primerd.prime.com
More information about the Comp.lang.c
mailing list