Skip to content

Commit e7d3de0

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

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-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,11 @@ defmodule Float do
422422
end
423423
end
424424

425+
# TODO remove once we require Erlang/OTP 27+
426+
# This function tricks the compiler to avoid this bug in previous versions:
427+
# https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/float.ex#L408-L412
428+
defp minus_zero, do: -0.0
429+
425430
defp decompose(significant, initial) do
426431
decompose(significant, 1, 0, initial)
427432
end

0 commit comments

Comments
 (0)