- From: "Matthew Halfant" <halfant@xxxxxxx>
- Date: Tue, 05 Jul 2005 16:40:50 GMT
I agree with the approach -- compute pi to the requested precision rather
than depend on a stored constant. Ironically, acos(-1.0d0) only returns an
accurate value if it tests for an argument of -1.0d0 and returns a stored
value of pi. If it tries to compute it, the answer won't be better than
single-precision accuracy. For example, the code
print *,acos(-1.d0 + epsilon(1.d0))
end program test
produces the value 3.14159263251637.
The problem arises because acos(x) has a vertical tangent at x = -1. For
this reason I use
pi = 4*atan(1.d0)
which at least CAN calculate an accurate answer without resorting to lookup.
"Michael Metcalf" <michaelmetcalf@xxxxxxxxxxxxxx> wrote in message
> > You have to define it yourself, and it will be defined in whatever
> > precision you chose....
> > e.g.
> > INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(P=11)
> > REAL (KIND=DP), PARAMETER :: pi =
> > 3.141592653589793238462643383279502884197_DP
> This risks mistyping. You can get it to machine precision by:
> double precision pi
> pi = acos(-1.0d0)
> This has to be, however, a variable rather than a named constant (in
> 95 but not Fortran 2003).
> Mike Metcalf
- Re: Pi.
- From: Richard Edgar
- Re: Pi.
- Prev by Date: Re: Pi.
- Next by Date: Re: Pi.
- Previous by thread: Re: Pi.
- Next by thread: Re: Pi.