Re: Precision Problem (Again...)



On Fri, 21 Sep 2007 12:58:26 +0000, Diego Signoretti wrote:

Hi all it's the first time for me on this group so please be kind...

I've got a problem with this fortran line.

VAR1 = -VAR2 * VAR3 / 2. / VAR4 * .3 / 21000000.

where all variables are REAL*8 and:

VAR2 = 1800.
VAR3 = 0.3174
VAR4 = 0.0191

well the problem is that the result is not what I expected infact:

1) the result is different from the output of a scientific calculator 2)
the result is different from the same code written in c++

Can you explain why?

A comment and a question...

The constants are single precision, try 2.0d0, 0.3d0 and 21000000.0d0, to
make them DP. Similarly, if var2, var3 and var4 are assigned by those
statements, they may or may not be 0 padded, try sticking a d0 at the end
of each of those assignments.

What do you get and what do you *expect* to get?

Bruce

.



Relevant Pages

  • Re: why cannot assign to function call
    ... with copy-like assignments semantics in other languages ... accounts for the frequent misunderstanding of Python ... and I don't know Perl well enough to judge). ... Even Fortran is still used in scientific computing circles ...
    (comp.lang.python)
  • Re: 2.0d0
    ... representable in binary form, it doesn't really matter if you write ... the assignments as ... in Fortran, 2.0 is exactly representable. ...
    (comp.lang.fortran)
  • Re: Fortran 77 Manual for beginners
    ... glen herrmannsfeldt wrote: ... Fortran 2003 reference manual and start reading, ... I certainly don't suggest sticking to F77, ...
    (comp.lang.fortran)
  • Precision Problem (Again...)
    ... Hi all it's the first time for me on this group so please be kind... ... I've got a problem with this fortran line. ... well the problem is that the result is not what I expected infact: ... the result is different from the output of a scientific calculator ...
    (comp.lang.fortran)
  • Variable Precision Problem
    ... Hi all it's the first time for me on this group so please be kind... ... I've got a problem with this fortran line. ... well the problem is that the result is not what I expected infact: ... the result is different from the output of a scientific calculator ...
    (comp.lang.fortran)