From 012fb44d3142c78c3b783321b6da4c90553df017 Mon Sep 17 00:00:00 2001 From: Rafael Simon Maia Date: Tue, 1 Oct 2024 10:07:30 -0600 Subject: [PATCH] Add Converged to infinite with negative condition (#3) * Add Converted to negative condition * Fix test * Decrease positive condition to 1 million * Correct comparisson * Revert test change --- lib/ex_xirr.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ex_xirr.ex b/lib/ex_xirr.ex index 33103db..e6a79b3 100644 --- a/lib/ex_xirr.ex +++ b/lib/ex_xirr.ex @@ -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)}