Re: Rounding off double precision
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Fri, 28 Mar 2008 21:36:17 -0700
Bamm <bammster@xxxxxxxxx> wrote:
On Mar 29, 11:43 am, Bamm <bamms...@xxxxxxxxx> wrote:
I'm trying some calculations in double precision, and I'd like the
output rounded off so that errors in calculation are not shown. For
instance, the result of COS(90 * 3.141592653589793238d0 / 180.) is
-4.37113886E-06. I'd like it to be zero. Thanks for any help.
For that matter, I also wonder why the result of Cosine is real and
not double precision. Thanks for any clarification.
Well...
1. You can't get "output rounded so that errors in calculation are not
shown." That is equivalent to asking for there to be no errors in
calculations. Ain't gonna happen. If you can establish what the order of
magnitude of the errors will be, then you can round the output
appropriately if you use an F edit descriptor. You aren't ever going to
get exactly zero out of an E edit descriptor (or list-directed output)
unless the number is indeed exactly zero.
2. The result of that particular COS *IS* double precision. If you are
seeing something else, then either a) you are misinterpreting the cause
of what you are seeing, or b) it is a compiler bug. I'd place my money
on (a). Quite a lot of it, and at good odds. :-) You need to show
exactly what is leading you to this conclusion. That means more than
just an isolated expression and an alleged result. I'd need to see a
complete program, most definitely including all declarations and
whatever output statement you used to get this result. For example,
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.
As an example of using an F edit descriptor to round, if I change the
program to
write (*,'(f15.12)') COS(90 * 3.141592653589793238d0 / 180.)
end
I then get
0.000000000000
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- References:
- Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Bamm
- Rounding off double precision
- Prev by Date: Re: Rounding off double precision
- Next by Date: Re: Rounding off double precision
- Previous by thread: Re: Rounding off double precision
- Next by thread: Re: Rounding off double precision
- Index(es):
Relevant Pages
|
|