C Floating point arithmetic

Andrew Koenig ark at alice.UucP
Fri Dec 6 16:13:12 AEST 1985

>>	float a,b;
>>	a = b + 1.0;	/* Gets done in double because 1.0 is a double.
>>			Gag me with a spoon. */
>Nah, gets done in single because the compiler realizes that 1.0 has
>the same representation in single and double, and therefore that
>the result of the addition will be the same.

... to which Dan Levy gives detailed evidence that his machine
does it in double.

Apparently some people don't recognize irony; let me try to make
the same point more clearly.

The point is that most floating-point constants are very simple: 1.0,
0.0, sometimes 2.0.  It doesn't take much to recognize such constants
and do the operations in single.  This is true even if your compiler isn't
up to it.

More information about the Comp.lang.c mailing list