Next: Order of Operations Matters
Up: Tipical pitfalls with floating
Previous: Cancellation (``Loss-of Significance'') Errors
  Contents
Consider the Fortran code
%{}
program test
real :: x=100000.0, y=100000.1, z
z = y-x
print*, 'z=',z
end program test
We would expect the output
but in fact the program prints (on Alpha ...)
Since single precision handles about 7 decimal digits, and the subtraction
cancels the most significant 6, the result contains only
one significant digit. The appended garbage 15625 are insignificant digits,
coming from the inexact binary representation of x and y.
Beware of convincing-looking results!
Adrian Sandu
2001-08-26