Skip to content

[3.12] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (GH-127216)#127530

Merged
gpshead merged 1 commit intopython:3.12from
miss-islington:backport-f41d8d8-3.12
Dec 2, 2024
Merged

[3.12] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (GH-127216)#127530
gpshead merged 1 commit intopython:3.12from
miss-islington:backport-f41d8d8-3.12

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Dec 2, 2024

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 f7bb658)

(cherry picked from commit f41d8d8)

Co-authored-by: Miss Islington (bot) [email protected]
Co-authored-by: Sergey B Kirpichev [email protected]

…_pow() (pythonGH-127211) (pythonGH-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 f7bb658)

(cherry picked from commit f41d8d8)

Co-authored-by: Miss Islington (bot) <[email protected]>
Co-authored-by: Sergey B Kirpichev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants