Re: calculation accuracy



Ben wrote:

I'm pretty new to fortran programming. I'm having a problem with the
accuracy of a simple computation:

I want to compute: sin(2*PI*100*0.1) but the answer that I'm getting
in fortran is quite a bit different than what I get in excel.

This is a sample program that I have:

PROGRAM test

REAL(8) :: A, B
DOUBLE PRECISION PI_D
PI_D = 3.1415927D0
A = sin(2.0*PI_D*10)
B = sin(2.0*PI_D*100.0*0.10)
PRINT *, A, B
END PROGRAM test

This program gives me A = 9.282041351020012E-007 and B = 1.864471717675201E-006.
> Why is there such a big difference? The answer
that excel gives is 9.28204135102001E-07.

I presume you know that the mathematical answer is zero,
and the difference between the two is only about 9e-7.

The main reason for the difference is that 0.10 is only
single precision, and is padded with zeros on conversion
to double precision for the multiply. You would get A
a lot closer to zero if P_D was closer to pi.

-- glen

.



Relevant Pages

  • Re: I =?ISO-8859-1?Q?don=B4t_view_the_value_right_afte?= =?ISO-8859-1?Q?r_six_decima
    ... You have reached the limit of precision available in Excel. ... There is only 15 significant digits available, after that zeros only. ... Claudio wrote: ...
    (microsoft.public.excel.misc)
  • Re: non-zero solution
    ... If you increase the precision even more, you just get closer and closer to zero as a solution, until you reach Excel's precision limits. ... Microsoft MVP - Excel ...
    (microsoft.public.excel)
  • Re: calculation accuracy
    ... a lot closer to zero if P_D was closer to pi. ... It seems sort of pointless to declare pi_d as double precision and ... also properly specify the literal as double precision, ...
    (comp.lang.fortran)
  • Re: Problem in Float Arithmetic
    ... and the meaning of "precision". ... It won't merely have more digits (precision), ... result will be closer to the mathematical result. ...
    (microsoft.public.vc.mfc)
  • Re: Pascal to Java questions
    ... You can get more precision in the offset from 1 than ... According to the API documentation, "log1pis much closer to the true ...
    (comp.lang.java.programmer)