Repository navigation
BUG: avoid integer arithmetic in the fv, pv and pmt powers - #174
Open
milliondreamsblog wants to merge 1 commit into
Open
milliondreamsblog wants to merge 1 commit into
milliondreamsblog wants to merge 1 commit into
Conversation
With integer rate and nper, (1 + rate) ** nper was evaluated with integer arithmetic, which wraps around on overflow and rejects negative exponents. Evaluate integer and boolean bases in float64. Decimal and other object inputs are unchanged. Closes numpy#173
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #173.
With integer
rateandnper,fv,pvandpmtcompute(1 + rate) ** nperwith integer arithmetic. That wraps around on overflow (2**64 is 0 in int64) and raises for negative exponents:This PR evaluates the power in float64 when its base is an integer or boolean array or NumPy scalar. Float inputs are unchanged, and so are
Decimalinputs and other object arrays; the existing Decimal tests still pass.It only changes how the power is computed, so it is independent of #166 and #170, which concern the dtype of
fv's output array. Until that lands,fvstill truncates fractional results for integerrate, which is why the newfvtest uses an example whose exact result is 1.@AtharvRG offered to pick this up on 31 October. As the reporter, I went ahead after a week without a PR; I'm happy to close this in favour of yours if you're close.
Tests: seven new tests in
TestIntegerRatescover the examples above,int32andint64arrays, and negative integernper. All seven fail on main and pass here. With a native build on Python 3.13.15 and NumPy 2.5.3 (Linux), 125 tests and doctests pass (118 on main), andruff check,mypy --no-incremental .andpyrightreport no issues.