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