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: Sine and Cosine Accuracy


Scott Robert Ladd writes:
 > Andrew Haley wrote:
 > > Try this:
 > > 
 > > public class trial
 > > {
 > >   static public void main (String[] argv)
 > >   {
 > >     System.out.println(Math.sin(Math.pow(2.0, 90.0)));
 > >   }
 > > }
 > > 
 > > zapata:~ $ gcj trial.java --main=trial -ffast-math -O 
 > > zapata:~ $ ./a.out 
 > > 1.2379400392853803E27
 > > zapata:~ $ gcj trial.java --main=trial -ffast-math   
 > > zapata:~ $ ./a.out 
 > > -0.9044312486086016
 > 
 > You're comparing apples and oranges, since C (my code) and Java differ
 > in their definitions and implementations of floating-point.

So try it in C.   -ffast-math won't be any better.

#include <stdio.h>
#include <math.h>

void
main (int argc, char **argv)
{
  printf ("%g\n", sin (pow (2.0, 90.0)));
}

Andrew.


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