This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: rs6000: floating point cast oddities?
- From: Linus Torvalds <torvalds at transmeta dot com>
- To: dalej at apple dot com, gcc at gcc dot gnu dot org
- Cc:
- Date: Mon, 17 Dec 2001 11:35:46 -0800
- Subject: Re: rs6000: floating point cast oddities?
- Newsgroups: linux.egcs
- Organization:
- References: <20011217181405.D75A97BBD@Nicole.fhm.edu>
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