From: Roberto Gennari on
Hi everyone.
I'm using Matlab since 4 years at my University and this is the first time I post here.
I was programming with Matlab just for solving a puzzle (in particular, looking for three numbers that have tha same product and sum in the interval 0.99-9.99) when I noticed this fact:
the sum of the three floating points number 1.25+1.62+2.8 is correctly 5.670000000000000 (using format long), and the product of the same numbers (in the same order (1.25*1.62*2.8) is 5.670000000000001. The problem is that if you write the product in this order 2.8*1.25*1.62 now you get 5.670000000000000 !!
This happens even with other permutations of the three numbers and it is has been a pain for me because it fails the if control ( actually matlab returns 0 if you ask 1.25+1.62+2.8==1.25*1.62*2.8 but it returns 1 with 1.25+1.62+2.8==2.8*1.25*1.62 !)
Does anybody know why this happens? I have already "solved" the problem rounding the numbers, but I really want to understand why!!

Thank you.

Roberto Gennari
Ferrara, Italy