This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: help understanding behaviour of unsuffixed float constants
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Regan, Brian (EPC COE)" <brian dot regan at honeywell dot com>
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Date: Thu, 22 May 2014 21:27:22 +0200
- Subject: Re: help understanding behaviour of unsuffixed float constants
- Authentication-results: sourceware.org; auth=none
- References: <61F2AE955326E042B27D898DD66AE04B33F0C890 at DE08EX3006 dot global dot ds dot honeywell dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, May 22, 2014 at 07:16:43PM +0000, Regan, Brian (EPC COE) wrote:
> I wonder if someone could help shed light on this for me.
Why do you think this is a problem? Conversion from float to double
can't raise any exceptions, no bits are lost, and
(double) a < 200.0
and
a < 200.0f
have the exact same set of floating point values for which the condition
is true resp. false. So, the compiler chooses to optimize and narrow
the comparison back to float comparison instead of double.
> static float a = 100.0;
> Also, the binary value of the constant 100.0 is compiled into 32 bits only.
Sure, because you initialize a float with 100.0, therefore it needs to be
converted.
In any case, this should have been posted to gcc-help, it has nothing to do
with development of gcc.
Jakub