On Sat, Sep 15, 2012 at 7:30 AM, Tijl Coosemans <tijl_at_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 ....................................................... Output of the following program is different : #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 ; 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 ....................................................... Reduction of argument once more did NOT change results : #include <math.h> #include <stdio.h> #include <stdlib.h> int main( int argc, char **argv ) { double d ; double two_pi ; double f ; double v ; double g ; double w ; two_pi = 2 * 3.14159265358979323846 ; d = strtod( argv[ 1 ], NULL ); printf( " given : %e\n", ( double ) d ); 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 )); f = floor ( d / two_pi ) ; v = d - f * two_pi ; printf( "multiplier : %e\n", ( double ) f ); printf( " reduced : %e\n", ( double ) v ); 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 )); g = floor ( v / two_pi ) ; w = v - g * two_pi ; printf( "multiplier : %e\n", ( double ) g ); printf( " reduced : %e\n", ( double ) w ); printf( " cos ( %e ) : %e\n", w , ( double ) cos( w )); printf( "cosf ( %e ) : %e\n", w , ( double ) cosf( w )); printf( "cosl ( %e ) : %e\n", w , ( double ) cosl( w )); return( 0 ); } 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 ....................................................... Thank you very much . Mehmet Erol SanliturkReceived on Sat Sep 15 2012 - 13:39:24 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:30 UTC