maxpohlmann
Add a way to supress "matching on 0.0" warning
In our application, we have many structs that contain lists of floats and, especially in test, we often use pattern matching on these objects. (I know, not optimal, but it works for our purposes.) Since upgrading to Elixir 1.16, we get loads of warning “pattern matching on 0.0 is equivalent to matching only on +0.0 from Erlang/OTP 27+. Instead you must match on +0.0 or -0.0”. However, in our application, we never use -0.0 (which is true for most projects, I’d wager). Having to write +0.0 everywhere seems kinda ridiculous and confusing, since -0.0 is used in so few situations ever.
Instead, 0.0 being equivalent to +0.0 is exactly what we want. Rather than having to use +0.0 everywhere, I think it would make a lot of sense to add an option to explicitly acknowledge this equivalence and thereby disable this warning. Perhaps one could add a compiler flag?
Most Liked
kip
You can see the rationale for the change here.
Basically IEEE754 floats have a different binary representation for +0.0 and -0.0. Equality comparisons like =/2 ignore the sign (as expected by IEEE754). But now exact comparisons like the match operator and erlangs =:=/2 will return false.
In the few cases I had I change from the matching to a guard clauses and it was a quick and backwards compatible change. But I can understand it would be a bigger issue if you have many many cases to adjust.







