next up previous contents
Next: Integer Multiplication Up: Tipical pitfalls with floating Previous: Insignificant Digits   Contents

Order of Operations Matters

Mathematically equivalent expressions may give different values in floating point, depending on the order of evaluation. For example
program test
  real :: x=12345.6, y=45678.9, z=98765432.1
  real :: w1, w2
  w1 = x*y/z
  w2 = y*(x*(1.0/z))
  print*, w1-w2
end program test
Mathematically, the difference between w1 and w2 should be zero, but on Alpha ... it is about .

Adrian Sandu 2001-08-26