Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Sep 2012 09:20:05 -0700
From:      Mehmet Erol Sanliturk <m.e.sanliturk@gmail.com>
To:        Tijl Coosemans <tijl@coosemans.org>
Cc:        toolchain@freebsd.org, current@freebsd.org
Subject:   Re: Clang as default compiler November 4th
Message-ID:  <CAOgwaMtxXtFLtxsk=vqSF6_5P5EZ-gEYp3ru0epTGSMTbEpZ1Q@mail.gmail.com>
In-Reply-To: <505883E3.3050103@coosemans.org>
References:  <504F5101.8090906@FreeBSD.org> <505101C3.70203@freebsd.org> <20120913020833.GA8255@troutmask.apl.washington.edu> <1347550332.1110.108.camel@revolution.hippie.lan> <20120913161024.GA13846@troutmask.apl.washington.edu> <20120914202319.GB5244@lor.one-eyed-alien.net> <20120915001808.GA70215@troutmask.apl.washington.edu> <20120915010600.GA70426@troutmask.apl.washington.edu> <20120915124809.GA10939@freebsd.org> <50548736.9030203@coosemans.org> <20120915140933.GA17801@freebsd.org> <505490FB.2000807@coosemans.org> <CAOgwaMvtSXoGCYnX%2BA3DzMffXo6mhHk=EWWO=1k7SWuAiH21xg@mail.gmail.com> <505883E3.3050103@coosemans.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Sep 18, 2012 at 7:23 AM, Tijl Coosemans <tijl@coosemans.org> wrote:

> On 15-09-2012 17:39, Mehmet Erol Sanliturk wrote:
> > On Sat, Sep 15, 2012 at 7:30 AM, Tijl Coosemans <tijl@coosemans.org>
> wrote:
> >> On 15-09-2012 16:09, Roman Divacky wrote:
> >>> Is this correct?
> >>>
> >>> lev ~$ ./cos 1.23456789e20
> >>> 6.031937e-01
> >>> -9.629173e-02
> >>> 2.814722e-01
> >>
> >> Yes, that's what the libm call returns.
> >
> > Linux z 3.5.3-1.fc17.x86_64 #1 SMP Wed Aug 29 18:46:34 UTC 2012 x86_64
> > x86_64 x86_64 GNU/Linux
> >
> > clang version 3.0 (tags/RELEASE_30/final)
> > Target: x86_64-redhat-linux-gnu
> > Thread model: posix
> >
> >
> > Output of the initial program is the following :
> >
> > #include <math.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > int
> > main( int argc, char **argv ) {
> >         double d = strtod( argv[ 1 ], NULL );
> >
> >         printf( " cos : %e\n", ( double ) cos( d ));
> >         printf( "cosf : %e\n", ( double ) cosf( d ));
> >         printf( "cosl : %e\n", ( double ) cosl( d ));
> >         return( 0 );
> > }
> >
> >
> > cos : 2.814722e-01
> > cosf : -9.629173e-02
> > cosl : 7.738403e-01
>
> This is probably because SSE instructions are used on amd64.
>
> > Output of the following program is different :
>
> The reason is that...
>
> > #include <math.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > int
> > main( int argc, char **argv ) {
> >         double d ;
> >         double two_pi ;
> >         double f ;
> >         double v ;
> >
> >     two_pi = 2 * 3.14159265358979323846 ;
> >         d = strtod( argv[ 1 ], NULL );
> >
> >     f = floor ( d / two_pi ) ;
> >         v = d - f * two_pi ;
>
> ...this is a poor way to compute a remainder. Try to use fmod() or
> remainder() instead.
>


My C knowledge is NOT very well . Thanks .



>
> >         printf( "  given : %e\n", ( double ) d );
> >         printf( "  multiplier : %e\n", ( double ) f );
> >         printf( "reduced : %e\n", ( double ) v );
> >
> >
> >         printf( " cos ( %e ) : %e\n", d , ( double ) cos( d ));
> >         printf( "cosf ( %e ) : %e\n", d , ( double ) cosf( d ));
> >         printf( "cosl ( %e ) : %e\n", d , ( double ) cosl( d ));
> >
> >
> >         printf( " cos ( %e ) : %e\n", v , ( double ) cos( v ));
> >         printf( "cosf ( %e ) : %e\n", v , ( double ) cosf( v ));
> >         printf( "cosl ( %e ) : %e\n", v , ( double ) cosl( v ));
> >
> >
> >     return( 0 );
> > }
> >
> >
> >   given : 1.234568e+20
> >   multiplier : 1.964876e+19
> > reduced : 1.638400e+04
> >
> >
> >  cos ( 1.234568e+20 ) : 2.814722e-01
> > cosf ( 1.234568e+20 ) : -9.629173e-02
> > cosl ( 1.234568e+20 ) : 7.738403e-01
> >
> >  cos ( 1.638400e+04 ) : -8.285342e-01
> > cosf ( 1.638400e+04 ) : -8.285342e-01
> > cosl ( 1.638400e+04 ) : -8.285342e-01
>
>
My intention was to check whether there is a difference between Clang
compiled programs in different operating systems .


The GCC output is as follows :


Linux z 3.5.3-1.fc17.x86_64 #1 SMP Wed Aug 29 18:46:34 UTC 2012 x86_64
x86_64 x86_64 GNU/Linux

cc (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

     given : 1.234568e+20
 cos ( 1.234568e+20 ) : 2.814722e-01
cosf ( 1.234568e+20 ) : -9.629173e-02
cosl ( 1.234568e+20 ) : 7.738403e-01

multiplier : 1.964876e+19
   reduced : 1.638400e+04
 cos ( 1.638400e+04 ) : -8.285342e-01
cosf ( 1.638400e+04 ) : -8.285342e-01
cosl ( 1.638400e+04 ) : -8.285342e-01

multiplier : 2.607000e+03
   reduced : 3.735904e+00
 cos ( 3.735904e+00 ) : -8.285342e-01
cosf ( 3.735904e+00 ) : -8.285342e-01
cosl ( 3.735904e+00 ) : -8.285342e-01


This shows that GCC is NOT better than Clang .

Thank you very much .

Mehmet Erol Sanliturk



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOgwaMtxXtFLtxsk=vqSF6_5P5EZ-gEYp3ru0epTGSMTbEpZ1Q>