Re: Rounding off double precision



Yes! You are expecting calculations done with floating point numbers
to be EXACT. Such calculations are actually approximate. Each
operation has a small quantity of error built in. That's the nature of
floating point.

No I am not. I understand how (binary) floating points are used to
represent actual (decimal) numbers. If I thought they were exact, I
wouldn't be asking how to round it off properly so that the errors are
not shown.

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. Thus rounding off its value
to real. I realized that after studying Richard Maine's short program,
which gave me a smaller answer of 6.12303177E-17 in the expected range
of precision.

Now that I have a value in the range E-17 instead of E-06, I can now
use F15.12 to round it off! My question has been answered. Thanks to
all who helped!
.



Relevant Pages

  • Re: Decimal Floating Point (was Re: why still use C?)
    ... Given the intrinsic nature of floating point, ... >> point representation no longer matters (only the precision is relevant). ... And what is the exact result of dividing 1 penny by 3, ... Dan Pop ...
    (comp.lang.c)
  • Re: Precision issue?
    ... be expecting exact answers from floating point airthmetic; ... Floating point arithmetic on all current ... The resolution of single precision floating point on most ...
    (comp.lang.fortran)
  • Re: double is integer?
    ... floating-point representation of what they typed. ... Floating point arithmetic has a loose grasp of the concept of precision. ... Any attempts to determine if a floating point value is an exact integer are probably ...
    (microsoft.public.vc.mfc)
  • Re: Precision
    ... Whether one does the subsequent calculations in internal ie integer format ... I have always used external format with Precision 4 since my ... floating point calcs which are done in binary have around 3% error albeit at ... positions it is IMPOSIBLE to have a result of 4 decimals with the 2 ...
    (comp.databases.pick)
  • Re: HPGCC 2: sat_decode_real
    ... > on the other hand if you take double precision -well it's a good ... > Metakernel does have exact mode -it keeps rational numbers in equation type. ... decimal digits in the numerator and denominator. ...
    (comp.sys.hp48)