Pointing Float

Andrew Koenig ark at alice.UucP
Tue Dec 17 16:29:18 AEST 1985

>>> >>	float a,b;
>>> >>
>>> >>	a = b + 1.0;	/* Gets done in double because 1.0 is a double.
>>> >>			Gag me with a spoon. */

> One spoon coming up!

>>> > 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.

> Try as I might, I could not generate any single precision instruxions.
> I even tried stuff like `a += 1.0' and `a++'. Would that `twere so.

>>> 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.)

> Agreed. But beware of the word `implicit'. Normally char's & short's
> get promoted to int's even when combined with themselves, but using
> the `++', `--', or `op=' forms will do the operation entirely in
> the shorter length. This is/was a big concern of some implementations
> of C on say, a z80, where one does not want to extend a char to an
> int just to mask it with the constant 037.
>> I really wish people would NOT POST if they don't know what
>> they're talking about.  Andy Koenig, as usual, gave a correct
>> answer and some turkey, as usual, contradicts him.  Sheesh.

> I couldn't agree more with the intent of this statement. People,
> before posting, *ask the machine* after you RTFM.

> Unfortunately, you picked the wrong time to post that. Andy is
> usually right, but not this time. (Well maybe he is if he has
> something other than a 4.2 BSD VAX). I agree he *should* be.


Let me set the record straight.

First, I had intended my comment beginning "Nah, gets done in single..."
as semi-facetious, semi-wishful-thinking.  If I had written it out fully,
it would have gone somewhat like this:

	"Yes, the language says it should be done in double.  However,
	 it is possible for even a fairly stupid compiler to recognize
	 that in many cases of this sort it is possible to obtain
	 exactly the same results by doing the operation in single,
	 and the compiler can reasonably do it in single without
	 butchering the language."

Now, obviously what ACTUALLY happens is up to your particular

However, I will go so far as to point out that the compiler on my
machine does both a=a+1.0  and a=b+1.0   in single.

More information about the Comp.lang.c mailing list