Skip to content

Conversation

@sabiwara
Copy link
Contributor

The conditionals returning -0.0 or 0.0 were triggering this bug: erlang/otp#7168.
We can trick the compiler to avoid this optimization through an extra private function.


# TODO remove and replace by assert once we require Erlang/OTP 27+
# We can't easily distinguish between -0.0 and +0.0 on previous version
defmacrop float_assert({:===, _, [left, right]}) do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with this approach because it gives us:

  • useful assertions
  • useful error messages on failure
  • can easily be removed since it is not here to stay

@sabiwara sabiwara merged commit e6aefcd into elixir-lang:main Feb 23, 2024
@sabiwara sabiwara deleted the float_round_zero branch February 23, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants