Re: Rounding off double precision
- From: Bil Kleb <Bil.Kleb@xxxxxxxx>
- Date: Sat, 29 Mar 2008 07:59:52 -0400
Bamm 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.
You may want to investigate using fixed-point arithmetic?
http://en.wikipedia.org/wiki/Fixed-point_arithmetic
For that matter, I also wonder why the result of Cosine is real and
not double precision. Thanks for any clarification.
Don't know; here's what I'm seeing:
program precision_trial
integer, parameter :: dp = selected_real_kind(15,307)
integer, parameter :: sp = selected_real_kind(6,37)
write(*,*) cos( 90 * 3.141592653589793238_dp / 180. )
write(*,*) cos( 90 * 3.141592653589793238_sp / 180. )
end program precision_trial
$ g95 precision_trial.f90 && ./a.out
6.123256244561421E-17
-4.371139E-8
$ gfortran precision_trial.f90 && ./a.out
6.123233995736766E-017
-4.3711388E-08
$ g95 -v
gcc version 4.0.3 (g95 0.90!) Mar 7 2008
$ gfortran --version
GNU Fortran (GCC) 4.3.0 20070713 (experimental)
Regards,
--
http://twitter.com/bil_kleb
.
- References:
- Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Bamm
- Rounding off double precision
- Prev by Date: Re: F2003 standard: Can Class(*) be used in generic proogramming?
- Next by Date: Re: F2003 standard: Can Class(*) be used in generic proogramming?
- Previous by thread: Re: Rounding off double precision
- Next by thread: Re: Rounding off double precision
- Index(es):
Relevant Pages
|
|