Pointing Float

COTTRELL, JAMES cottrell at nbs-vms.arpa
Sun Dec 15 03:58:47 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.

But I think you owe some turkey an apology and are left eating crow.

	jim		cottrell at nbs
*/
------



More information about the Comp.lang.c mailing list