rs6000: floating point cast oddities?

Linus Torvalds torvalds@transmeta.com
Mon Dec 17 11:48:00 GMT 2001


In article <F7313696-F31C-11D5-9F61-003065C86F94@apple.com> you write:
>On Monday, December 17, 2001, at 09:07 AM, degger@fhm.edu wrote:
>>
>> float
>> foo (float a, float b)
>> {
>>   return b+1.0;
>> }
>
>No, according to the language 1.0 is double, and the addition
>should therefore be done in double.  You can write 1.0f to
>specify a float 1.0.

Clearly, yes.

But at the same time from an optimization standpoint wouldn't it make
sense to do the optimization of keeping it in float format _iff_

 - the architecture makes it faster (some don't care, so it isn't an
   optimization)

 - the double constant is exactly representable in float (like 1.0 is
   here)

Can the end result ever change (remember, we cast it back to float after
the operation, and both sides of the addition are representable as
float)?

If the architecture does IEEE fp for floats, I thought the following
held true:

  (float)(float + float) = (float)((double)float + (double)float)

including all the overflow and special cases.

		Linus



More information about the Gcc mailing list