BUG: integer power overflow in fv, pv and pmt
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- numpy, python
調査の方向性
Start with numpy_financial/_financial.py, the source file named in the issue, and inspect the power calculations used by fv, pv and pmt. Reproduce the supplied integer-rate examples and compare them with the floating-rate outputs; done means the integer-rate calls give equivalent finite results while preserving Decimal support.
索引モデルが issue の本文から書いたものです。
説明
Describe the issue:
With integer rate and nper, fv, pv and pmt can overflow while computing (1 + rate) ** nper. Changing only rate from 1 to 1.0 gives the expected results in the examples below.
This is related to #166. I checked the source at PR #170's head (27ab9b4): it fixes the three examples in #166, but these still fail. Its change gives fv a floating output buffer; the power is still evaluated with integer arithmetic. pv and pmt are affected too.
Reproduce the code example:
import numpy_financial as npf
for rate in (1, 1.0):
print(f"rate={rate!r}")
print("fv: ", float(npf.fv(rate, 64, 0, -2.0**-64)))
print("pv: ", float(npf.pv(rate, 64, -1, 0)))
print("pmt:", float(npf.pmt(rate, 64, 1)))
Output on 1.1.0, current main, and PR #170's head:
rate=1
fv: 0.0
pv: -inf
pmt: -0.0
rate=1.0
fv: 1.0
pv: 1.0
pmt: -1.0
Both calls should give the floating-rate results, within rounding. The exact FV is 2**-64 * 2**64 = 1, so the final result fits even in an integer output buffer. The exact PV is 1 - 2**-64, and PMT is -1 / (1 - 2**-64); both round to the values above in float64. I also checked these against Python's fractions.Fraction arithmetic.
Here 1 and 1.0 both mean 100% per period. The high rate and 64 periods are deliberate: they make the integer overflow easy to reproduce while keeping the expected outputs finite and small.
Error message:
The integer-rate pv call emits:
RuntimeWarning: divide by zero encountered in scalar divide
The fv and pmt calls return the wrong values without a warning.
Runtime information:
Checked on 30 October 2026 with Python 3.13.5, NumPy 2.5.3 and numpy-financial 1.1.0 on 64-bit Windows 11. NumPy's default integer dtype is int64.
I also ran the examples using the unmodified _financial.py from:
Those were focused source-module checks in the same environment, not full package builds or full test-suite runs.
Context for the issue:
In this environment, NumPy evaluates the intermediate 2**64 as an int64 and wraps it to zero. Promoting the output buffer cannot recover that value. Could the power calculation use a suitable promoted dtype before exponentiation, while preserving the existing Decimal support?
Using a floating-point rate avoids the problem in these examples.
- 主要言語
- Python
- スター
- 416
- フォーク
- 112
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
numpy/numpy-financial のほかの issue
-
An integer `rate` truncates `fv` to an integer and makes `ipmt`/`ppmt` raise対応中かも @naseweisssss が 38 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
numpy/numpy-financial#166 ·
-
Add CUMPRINC and CUMIPMT functions対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンenhancement sustain-2026
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
numpy/numpy-financial#38 · コメント 6 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
numpy/numpy-financial#131 · コメント 1 件 ·
-
documentation sustain-2026
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
numpy/numpy-financial#130 · コメント 8 件 ·
-
BUG: rate returning incorrect value対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
numpy/numpy-financial#126 · コメント 4 件 ·
numpy/numpy-financial の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OStrama/weishaupt_modbus#216 ·
-
bug follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
Retire stale Python-parity labels in Rust ingress and auth tests対応中かも @github-actions が今日担当しました。 オープンfactory factory:building factory:unowned ralph-status:in-progress via:opencode-free/hy4-flash-free
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
JoshCLWren/comic-pile#5874 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
area: community lane: free-agent priority: P1 roadmap type: task
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
velella-sh/offing#1046 ·
メンテナーはふだん 1 日以内に返信