Re: Rounding off double precision
- From: Charles Coldwell <coldwell@xxxxxxxxx>
- Date: Sun, 30 Mar 2008 13:21:05 GMT
glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> writes:
Bamm wrote:
(snip)
However I have since found where I went wrong. I was using
double precision Speed, Azimuth, V
Azimuth = 90.
parameter(Pi = 3.141592653589793238d0)
V = Speed * cos(Azimuth * Pi / 180.)
print *, V
The problem with the unusually large value of -4.37113886E-06 arose
because I didn't declare Pi to be double precision, even though I
assigned a double precision value to it.
This problem might be more likely to occur to ex-C programmers.
C uses #define is places where Fortran uses PARAMETER,
but #define is typeless.
There's a little more to it than that. In C, the literal constant "0.1"
has type double precision, in Fortran, the literal constant "0.1" has
type single precision. So
double x = 0.1;
in C gives x the double precision value
+1.600000000000000088817841970012523233890533447265625 / 16
whereas
DOUBLE PRECISION X
X = 0.1
in Fortran gives X the single precision value
+1.60000002384185791015625 / 16
Actually, now that I look at it, the OP actually had the opposite
problem, analogous to
X = 0.1D0
where X is implicitly typed default real (single precision), but the
literal constant has type double precision.
Chip
--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"
GPG Key ID: 852E052F
GPG Key Fingerprint: 77E5 2B51 4907 F08A 7E92 DE80 AFA9 9A8F 852E 052F
.
- Follow-Ups:
- Re: Rounding off double precision
- From: glen herrmannsfeldt
- Re: Rounding off double precision
- References:
- Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Richard Maine
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: e p chandler
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: glen herrmannsfeldt
- Rounding off double precision
- Prev by Date: Re: FoX - an XML toolkit for Fortran
- Next by Date: Re: FoX - an XML toolkit for Fortran
- Previous by thread: Re: Rounding off double precision
- Next by thread: Re: Rounding off double precision
- Index(es):
Relevant Pages
|
|