Skip to content

Commit

Permalink
Add Converged to infinite with negative condition (#3)
Browse files Browse the repository at this point in the history
* Add Converted to negative condition

* Fix test

* Decrease positive condition to 1 million

* Correct comparisson

* Revert test change
  • Loading branch information
rafaelsimonmaia authored Oct 1, 2024
1 parent 68eedd2 commit 012fb44
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/ex_xirr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ defmodule ExXirr do
@spec calculate(atom(), list(), float(), float(), integer()) ::
{:ok, float()} | {:error, String.t()}

defp calculate(:xirr, _, _, rate, _) when rate > 1_000_000_000,
defp calculate(:xirr, _, _, rate, _) when rate > 1_000_000,
do: {:error, "Converged on infinity."}

defp calculate(:xirr, _, _, rate, _) when rate < -1_000_000,
do: {:error, "Converged on infinity."}

defp calculate(:xirr, _, acc, rate, _) when acc in [-0.0, +0.0], do: {:ok, Float.round(rate, 8)}
Expand Down

0 comments on commit 012fb44

Please sign in to comment.