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 Post!

D4no0

D4no0

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

Most Liked

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.

Last Post!

Where Next?

Popular in Proposals: Ideas Top

derekkraan
I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked w...
New
caslu
Recently (last week) this PR was merged in Ruby on Rails repository and i thought it could be nice to have in phoenix, basically what it ...
New
shahryarjb
When proposing or suggesting something please consider: As my experience implementing getBoundingClientRect as Phoenix.LiveView.JS funct...
New
andreamancuso
Hey folks, This might sound niche, but I think it’s worth bringing up - especially given Phoenix’s reputation for being lightweight, por...
New
sezaru
When writing my code, I always find __MODULE__ very useful to use as alias of that module “inner dependencies”, ex: alias __MODULE__.{Im...
New
spicychickensauce
I’ve previously explored what is possible today with hacks to implement view transitions in our apps: I have since created a fork to im...
New
eagle-head
Hi everyone, I’ve been researching Content Security Policy Level 3 support in Phoenix and wanted to share my findings and a proposal for...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement