Skip to content

Commit

Permalink
pattern matching on 0.0 is equivalent to matching only on +0.0 from E…
Browse files Browse the repository at this point in the history
…rlang/OTP 27+. Instead you must match on +0.0 or -0.0
  • Loading branch information
nathany-copia committed Sep 26, 2024
1 parent 271acee commit d60bd95
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ex_xirr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ defmodule ExXirr do

@spec calculate(atom(), list(), float(), float(), integer()) ::
{:ok, float()} | {:error, String.t()}
defp calculate(:xirr, _, 0.0, rate, _), do: {:ok, Float.round(rate, 6)}
defp calculate(:xirr, _, acc, rate, _) when acc in [-0.0, +0.0], do: {:ok, Float.round(rate, 6)}
defp calculate(:xirr, _, _, -1.0, _), do: {:error, "Could not converge"}
defp calculate(:xirr, _, _, _, 300), do: {:error, "I give up"}

Expand Down
2 changes: 1 addition & 1 deletion lib/legacy_finance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule LegacyFinance do
acc * first_value_sign(dates_values)
end

defp calculate(:xirr, _date_values, 0.0, {rate, _bottom, _upper}, _tries) do
defp calculate(:xirr, _date_values, acc, {rate, _bottom, _upper}, _tries) when acc in [-0.0, +0.0] do
{:ok, Float.round(rate, 6)}
end

Expand Down

0 comments on commit d60bd95

Please sign in to comment.