Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is something people are living with because it's very rare to use exact equality tests on floats in BI applications to begin with. Far more people want to look at the sum of order amounts, or at orders where the amount is within a certain range, than at orders where amount is exactly equal to some random float.


People are living with it until they stumble when an innocent expression

   (a + b) >= c 
suddenly fails to work. For instance, in Excel the expression

   A1-B1-C1 >= 0
returns FALSE when A1=2.03, B1=0.03, and C1=2. Such an expression can be used for instance to filter records that fall within a certain range, and that filter would produce wrong results.


It would lead to some hilarious malpractise if anyone understood floating point and stole a billion cents. Things like this has happend and will continue if people arent aware of floating point error.


> of floating point error.

Worth noting that this is a risk whenever there is rounding, if this chain of logic happens with cents as ints, it is still wrong:

    1 / 2 => 0
    0 * 2 => 0
Therefore:

    1 == 0




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: