C Floating point arithmetic

Roger Rose rlr at stcvax.UUCP
Fri Dec 6 08:39:04 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.

Sorry, it get's done in double.  ALL floats are converted to double prior
to any operation.  (Refer to K&R p. 41 on implicit type conversions.)

Roger Rose
   UUCP:    {hao ihnp4 decvax}!stcvax!rlr
   USnail:  Storage Technology Corp. - MD 3T / Louisville, Co.  80028
   phone:   (303) 673-6873

More information about the Comp.lang.c mailing list