Skip to content

Commit 0828e17

Browse files
committed
Fix unexpected rounding signs on OPT26-
1 parent d6021e4 commit 0828e17

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: lib/elixir/lib/float.ex

+7-3
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ defmodule Float do
374374
case rounding do
375375
:ceil when sign === 0 -> 1 / power_of_10(precision)
376376
:floor when sign === 1 -> -1 / power_of_10(precision)
377-
:ceil when sign === 1 -> -0.0
378-
:half_up when sign === 1 -> -0.0
377+
:ceil when sign === 1 -> minus_zero()
378+
:half_up when sign === 1 -> minus_zero()
379379
_ -> 0.0
380380
end
381381

@@ -406,7 +406,7 @@ defmodule Float do
406406

407407
cond do
408408
num == 0 and sign == 1 ->
409-
-0.0
409+
minus_zero()
410410

411411
num == 0 ->
412412
0.0
@@ -422,6 +422,10 @@ defmodule Float do
422422
end
423423
end
424424

425+
# Tricking the compiler to avoid this bug in versions before OTP27
426+
# https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/float.ex#L408-L412
427+
defp minus_zero, do: -0.0
428+
425429
defp decompose(significant, initial) do
426430
decompose(significant, 1, 0, initial)
427431
end

0 commit comments

Comments
 (0)