maxpohlmann

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?

First 4 of 4 Posts Switch mode

D4no0

D4no0

Damn, what the? What is the actual point of -0.0 and why it’s signed?

kip

kip

ex_cldr Core Team

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.

maxpohlmann

maxpohlmann OP

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.

— All posts loaded —

Where Next?

Trending in Proposals: Ideas Top

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement