Re: Rounding off double precision



On Mar 29, 12:48 am, Bamm <bamms...@xxxxxxxxx> 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?

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.

To start with, you can not represent the EXACT value of PI with a
finite number of bits. It only gets worse from there. :-).

- e

.



Relevant Pages

  • Re: Help with floating point non-reversibility
    ... state that you might want to restore later. ... Don't use floating point math to "back out" the change: ... Doesn't suck at all. ...
    (comp.programming)
  • Re: Help with floating point non-reversibility
    ...   define fold-into (probs votes prob) ... Is there some obvious way to write this so I can still use floating ... probabilities of the election result can only ...
    (comp.programming)
  • Re: problem returning floating point
    ...   int i; ... As long as the floating point type has enough ... float, the floating point value will hold the exact answer just like ...
    (comp.lang.c)
  • Re: --- --- Irrational solutions
    ...    about m,n but not a declaration of their types in the hypothesis. ... specifications for the missing declarations, your assertion is false, ... No, they are _all_ exact. ...
    (sci.math)
  • Re: Forth 200X - problem with file ttester.fs
    ... with compiling it with a system with no floating point. ...     DECIMAL ... when it fails to recognise the 0E in the third line. ...
    (comp.lang.forth)