This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc 4.6.1 double to long cast on 32bit systems


On Wed, Aug 1, 2012 at 1:52 PM, Karsten Ahnert
<karsten.ahnert@ambrosys.de> wrote:
>
> I am new to this list. If this is not the correct place for posting the
> question I apologize for any inconvenience.

This question should have gone to gcc-help@gcc.gnu.org.  Please take
any followups to gcc-help.  Thanks.

> The following code produces strange results on a 32 bit Linux system
> with gcc 4.6.1 (compilation with -m32):
>
> double val = 52.30582;
> double d = 3600.0 * 1000.0 * val;
> long l = long( d );
> long l2 = long( ( 3600.0 * 1000.0 * val ) );
> long l3 = (long)( 3600.0 * 1000.0 * val );
> long l4 = long( 3600.0 * 1000.0 * val );

x86 32-bit floating point is weird because by default the compiler
will use the 80-bit x87 floating point registers.  That will cause
unexpected results.  Ways to avoid that are -mfpmath=sse -msse2, or
-fexcess-precision=std, or -ffloat-store.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]