On Sat, Aug 22, 2015 at 1:32 PM, Alan McKinnon <alan.mckin...@gmail.com> wrote: > I can tell you that equality comparisons on floats are problematic, and > always will be due to how they are stored (double-precision floats, > inhernetly inexact). This is not a "problem" per se, it's a systemic > side effect of how our computers represent floats i.e. you can't "fix" > it as there is nothing to fix
It's not that floats are inherently "inexact"; it really has to do with trying to represent a base-10 number in a data structure designed to hold a base-2 number. If your number can be represented by some multiple of a power of 2, equality comparisons will work. If it cannot be, it has to be stored as an approximation. Someone else mentioned a "decimal" data type, which works much like a float but is designed for storing base-10 numbers.