The key mathematical property of equality is that a=b implies f(a)=f(b) for all possible functions f. It was a mistake of C++, C#, and Java to violate this. This is the ultimate cause of the conundrum @BarryRevzin discusses in https://brevzin.github.io/c++/2018/12/09/mixed-comparisons/ …
-
-
Similarly, given value x of type t, if a compiler allows automatic conversion to type u, then we should expect to have f(a)==f(u(a)) for all functions f, but most languages also violate this. Haskell and ML stand out as being honest about equality and conversions.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I wonder if Option<Double> has better semantics, tho IEEE754 fans repeat that came first and was worse. FWIW, making invalid elements unequal to themselves has precedents in math (PERs, or partial equivalence relations), tho learning PERs might not make floats less error-prone.
-
Here's a neat trick. Use IEEE 754 with -0==+0, but treat -inf == +inf == NaN, and modify a/b to be b-b+a/b to stop production of infinities. Now you have floating point math that obeys the equality axioms.
- 1 more reply
New conversation -
-
-
It also has -0 = 0, but 1/(-0) != 1/0, so IEEE made both mistakes. Mind you they did it for what they felt were good reasons, but the result is still a sad state of affairs.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
== is not equality but a decision procedure for equality. If floating point values are meant to represent reals, then inequality is only semidecidable, so you'd expect == to at best be able to tell you either "no" or "I don't know".
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This Tweet is unavailable.
-
This Tweet is unavailable.
- 1 more reply
-
-
-
It's interesting how a totally defensible decision that seems to greatly improve ergonomics leads you down a horrible rabbit hole of having to pick and choose what consistency you want to preserve. Neat blogs.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Basically what Go does. I've ported C -> Go some time ago (mostly math code) and it was difficult enough, a lot of expressions were splitted into several to make them more clear and find where different types were used.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.