Hello!
I'm not sure if this is a bug or if we are misusing the rate method. The method does not return when the number of payments (nper) is 1 and the amount per period (pmt) and the present value (pv) are passed in as BigDecimal (e.g. Exonio.rate(1, 100.0.to_d, -100.0.to_d)). I see the arguments are annotated as Floats but we have been we passing in BigDecimal for a few months and just now hit this edge-case.
Is there truly an issue with passing in BigDecimal? Could this also happen on other inputs since there is no circuit breaker on the number of times the method iterates to arrive at a value within the tolerance? We use this method in a financial context so we care about being precise and that's why we have opted to pass in BigDecimals.
I would appreciate your thoughts on this issue. Thanks!
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "exonio"
gem "minitest"
end
require "exonio"
require "minitest/autorun"
class Test < Minitest::Test
def test_rate_with_float
assert_equal Exonio.rate(1, 100.0, -100.0), 2.80332e-15
end
def test_rate_with_big_deicmal
assert_equal Exonio.rate(1, 100.0.to_d, -100.0.to_d), 2.80332e-15 # never returns
end
end
ruby 3.3.7 (2025-01-15 revision be31f993d7) [arm64-darwin24]
Hello!
I'm not sure if this is a bug or if we are misusing the
ratemethod. The method does not return when the number of payments (nper) is1and the amount per period (pmt) and the present value (pv) are passed in asBigDecimal(e.g.Exonio.rate(1, 100.0.to_d, -100.0.to_d)). I see the arguments are annotated as Floats but we have been we passing in BigDecimal for a few months and just now hit this edge-case.Is there truly an issue with passing in BigDecimal? Could this also happen on other inputs since there is no circuit breaker on the number of times the method iterates to arrive at a value within the tolerance? We use this method in a financial context so we care about being precise and that's why we have opted to pass in BigDecimals.
I would appreciate your thoughts on this issue. Thanks!
ruby 3.3.7 (2025-01-15 revision be31f993d7) [arm64-darwin24]