mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
[3.13] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (#127216)
Note, that transformed expression is not an equivalent for original one (1/exp(-x) != exp(x) in general for floating-point numbers). Though, the difference seems to be ~1ULP for good libm implementations.
It's more interesting why division was used from beginning. Closest algorithm I've found (no error checks, of course;)) - it's Algorithm 190 from ACM: https://dl.acm.org/doi/10.1145/366663.366679. It uses subtraction in the exponent.
(cherry picked from commit f7bb658124
)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
parent
511c588f5d
commit
f41d8d89e7
3 changed files with 8 additions and 1 deletions
|
@ -301,6 +301,11 @@ class ComplexTest(ComplexesAreIdenticalMixin, unittest.TestCase):
|
|||
except OverflowError:
|
||||
pass
|
||||
|
||||
# gh-113841: possible undefined division by 0 in _Py_c_pow()
|
||||
x, y = 9j, 33j**3
|
||||
with self.assertRaises(OverflowError):
|
||||
x**y
|
||||
|
||||
def test_pow_with_small_integer_exponents(self):
|
||||
# Check that small integer exponents are handled identically
|
||||
# regardless of their type.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue