Skip to content

Fix unexpected rounding signs on OPT26- #13365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2024

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.

@@ -5,6 +5,17 @@ defmodule FloatTest do

doctest Float

# 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.

None yet

2 participants