Re: Rounding off double precision



Bamm wrote:
when I run the complete program

write (*,*) COS(90 * 3.141592653589793238d0 / 180.)
end

using g95 on this Mac, I get

6.123256244561421E-17

which is about the expected accuracy for double precision.

Here's the answer I get for the same program above using g77 on Linux:

6.12303177E-17

Am I doing anything wrong?
Probably not, different compilers print out a different number
of digits for list directed output. The standard doesn't
specify how many digits to print out for an * format. If
you want to experiment, try an explicit format.

double precision T
real R
T = COS(90 * 3.141592653589793238d0 / 180.)
R = T
write (*, '(E20.15)' ) T, R
write (*, '(F10.5)' ) T, R
end

Try different format widths (the 10 or 20) and number of digits
(the 5 or 15) until you get something you like.

Also, it's not obvious, but for output, double precision values
are printed with an E exponent when you use the E edit descriptor.
You could try using D20.15. Some processors print this with a D
exponent, others use an E.


*** Hendrickson
.