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?

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.

Where Next?

Popular in Proposals: Ideas Top

Asd
Process.resolve/1 What it does Takes any possible name of the process and returns a pid of the process or port (or nil if none found). Si...
New
mudasobwa
I am not sure it deserves to be discussed in the mailing list, so I’d start here. assert/1 and/or refute/1 macros print the following er...
New
cevado
Being able to build nested relations in a schemaless changeset would be helpful to deal with complex forms on Phoenix without the need to...
New
mikesax
I was writing code that included a function I would call later (so it wasn’t called yet). I got a warning, and I thought I could put an u...
New
ffloyd
The Problem Currently, if I define a struct in the following way: defmodule MyStruct do # Both x and y will have the FIXED values unti...
New
7rans
I implemented Access behavior for a struct today. Pseudo-code… defmodule MyStruct do defstruct data: %{} @behaviour Access # ... ...
New
winsalva
Hello all. First of all i’m running this using termux on an android phone. Running mix assets.setup shows this message 06:54:08.450 [de...
New
nhpip
So the other day I was rearranging the supervisor hierarchy of our product and I had a thought. In addition to creating a child spec with...
New
Oliver
One common problem we face in constructing lists is that there is (AFAIK) no support for conditionally inserting members into list declar...
New
bartblast
This could resolve to {[a: 1, b: 2]}. Was it ever considered to allow such syntax? Notice this: {:abc, a: 1, b: 2} and this: my_fun(:abc,...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement