Re: calculation accuracy
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 Mar 2007 15:23:19 -0800
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
.
- Follow-Ups:
- Re: calculation accuracy
- From: Richard Maine
- Re: calculation accuracy
- References:
- calculation accuracy
- From: Ben
- calculation accuracy
- Prev by Date: Re: Profiling Fortran 77 using gprof on linux
- Next by Date: Re: calculation accuracy
- Previous by thread: calculation accuracy
- Next by thread: Re: calculation accuracy
- Index(es):
Relevant Pages
|