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?
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.
Thanks for the reply and the link! I definitely see the reasoning for changing the behaviour of +0.0 =:= -0.0. However, they write:
The warning can be suppressed by matching against +0.0 instead of 0.0.
I just think it would be nice to have a way to suppress the warning globally rather than on a case-by-case basis.
I understand, though, that our situation, where we indeed have many cases to adjust, isn’t that common and doesn’t warrant adding a way to suppress the warning by itself. But perhaps it’s more common than I think or there are more people that would like for 0.0 to be treated as +0.0 without warning, so I’ll leave this open for discussion.