Timeline for How to implement float hashing with approximate equality
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 13, 2019 at 21:05 | audit | First posts | |||
| May 13, 2019 at 21:06 | |||||
| Apr 30, 2019 at 12:24 | comment | added | HTNW |
@MSalters ? Presumably, sufficiently configurable static analysis tools can do what I suggested just fine. If a class has a float field that doesn't participate in ==, then don't configure your tool to warn on == on that class. If the class does, then presumably marking the class's == as "too exact" will cause the tool to ignore that sort of error within the implementation. E.g. in Java, if @Deprecated void foo(), then void bar() { foo(); } is a warning, but @Deprecated void bar() { foo(); } is not. Maybe many tools don't support this, but some might.
|
|
| Apr 30, 2019 at 9:58 | comment | added | MSalters |
@HTNW: That would be too simple. A ratio class might have a float approximation field which does not participate in ==. Besides, the static analysis tool will already give a warning inside the == implementation of classes when one of the members being compared is a float type.
|
|
| Apr 29, 2019 at 16:56 | comment | added | HTNW |
Addressing @OP's edit, I would add that the incorrectness of floating-point == should "infect" the == of types containing them. That is, if they follow your advice of providing an exact equality, then their static analysis tool should further be configured to warn when equality is used on Temperature. It's the only thing you can do, really.
|
|
| Apr 29, 2019 at 14:50 | comment | added | Ordous | @Christophe Interesting question. If you think about it, you'll see that this approach will make a single large equivalence class out of floats whose resolution is greater than epsilon (it's centered on 0, of course) and leave the other floats in their own class each. But that's not the point, the real problem is that whether it concludes that 2 numbers are equal depends on whether there is a third one compared and the order in which that is done. | |
| Apr 29, 2019 at 6:51 | comment | added | Christophe | interesting thoughts. So by accumulating millions of epsilon and with transitivity you can conclude that anything is equal to anything else :-) But does this mathematic constraint acknowledge the discrete foundation of floating points, which in many cases are approximations of the number they are intended to represent ? | |
| Apr 29, 2019 at 6:30 | history | answered | Sebastian Redl | CC BY-SA 4.0 |