1

We are currently experimenting with floating point numbers and came over a program in Fortran where we weren't able to figure out what happens.

program test
a=0.1
print*, a * .1 * 10.
print*, .1 * a * 10.
print*, .1 * 10. * a
end program test

Question: why does it produce different results?

0.100000009  
0.100000009  
0.100000001

We think that it could have something to do with the representation model of floating numbers (mantissa, exponent,...) and how the computer rounds numbers, but we are not sure.

Can someone explain how this works in detail?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Dan
  • 11
  • 2
  • 2
    http://stackoverflow.com/questions/19820297/why-does-changing-the-sum-order-returns-a-different-result – different language, (probably) same reason – JJJ May 01 '17 at 13:27
  • Rounding errors caused by the binary representation of the mantissa. These errors are very much dependent on the order of the multiplicands. – Paul Bentley May 01 '17 at 13:27

0 Answers0