Re: Rounding off double precision
- From: Herman D. Knoble <SkipKnobleLESS@xxxxxxxxxxxxxxx>
- Date: Mon, 31 Mar 2008 08:13:44 -0400
In your case, use of the F90 Floor function thus:
double precision :: x
x= COS(90 * 3.141592653589793238d0 / 180.)
! round(x) = foor(x+0.5D0)
write(*,*) floor(x+0.5D0)
end
when compiled and run will write 0.0
For Fortran 77 define Floor as:
DINT(X)=X-DMOD(X,1.D0)
FLOOR(X)=DINT(X)-DMOD(2.D0+DSIGN(1.D0,X),3.D0)
For borderline cases of rounding to the nearest whole number one
can use a Fortran rendition of the APL toleranat (that is, fuzzy))
Floor (and Round functions:
http://ftp.aset.psu.edu/pub/ger/fortran/hdk/eps.f90
(this includes a sample main program).
Skip Knoble
On Fri, 28 Mar 2008 20:43:53 -0700 (PDT), Bamm <bammster@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.
.
- Follow-Ups:
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- References:
- Rounding off double precision
- From: Bamm
- Rounding off double precision
- Prev by Date: Re: data with metadata
- 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
|
|