[718] in java-interest

home help back first fref pref prev next nref lref last post

trig precision problems?

daemon@ATHENA.MIT.EDU (Trevor Misfeldt)
Mon Jul 17 15:43:11 1995

Date: Mon, 17 Jul 95 10:40:23 PDT
From: misfeldt@mda.ca (Trevor Misfeldt)
To: java-interest@java.Eng.Sun.COM


In porting C++ programs to java, I came across a
problem in the accuracy of the java trigonmetric
functions.  As an example, I use sin() here.  
 
  double x = 0.5;
  double y = Math.sin( 0.5 );
  System.out.println( "y: " + y );
  double y2 = y - 0.4794; 
  System.out.println( "y2: " + y2 );
 
The above code fragment produces:

  y: 0.479426 
  y2: 2.55297e-05

which I have taken to be:

0.4794255297

BTW, the y2 variable is introduced here because I have not
figured out how to get better precision in the output of a
double. 

Now, an analagous C++ program (running on the same machine,
also with a double ) produces:

0.479425538604203

Similarly, an HP scientific calculator yields:

0.479425538604

A calculator tool produces:

0.479425538604


Although I have agreement to 7 significant digits, I need 
much better.  I have ported a function which produces 
results differing by up to 50% from the C++ implementation
because of the trig differences.


Questions
=========

Is this a display problem or a processing problem?

Can anyone else verify this?

Why does the Java sin function for double agree to only 7
significant digits with a C program when the float results
agree to 8 digits?

Is this discrepancy known and will it be fixed in an upcoming
release or am I stuck with this accuracy?


Cheers,
Trevor Misfeldt




-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post