Skip to content

Correct frexp() docs for non-finite numbers#149753

Open
skirpichev wants to merge 1 commit into
python:mainfrom
skirpichev:fix-frexp-docs
Open

Correct frexp() docs for non-finite numbers#149753
skirpichev wants to merge 1 commit into
python:mainfrom
skirpichev:fix-frexp-docs

Conversation

@skirpichev
Copy link
Copy Markdown
Member

The current version claims, that mantissa in such cases satisfies 0.5 <= abs(m) < 1. That's wrong:

>>> from math import frexp, inf, nan
>>> frexp(inf)
(inf, 0)
>>> frexp(-inf)
(-inf, 0)
>>> frexp(nan)
(nan, 0)

The current version claims, that mantissa in such
cases satisfies 0.5 <= abs(m) < 1.  That's wrong:

```pycon
>>> from math import frexp, inf, nan
>>> frexp(inf)
(inf, 0)
>>> frexp(-inf)
(-inf, 0)
>>> frexp(nan)
(nan, 0)
```
@skirpichev skirpichev added skip issue skip news needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels May 13, 2026
@skirpichev
Copy link
Copy Markdown
Member Author

CC @StanFromIreland per experts index.

@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32666117 | 📁 Comparing 22657c4 against main (a4e51c8)

  🔍 Preview build  

1 file changed
± library/math.html

@StanFromIreland
Copy link
Copy Markdown
Member

CC @StanFromIreland per experts index.

Hi Sergey, sorry but I'm not a math expert :-( The "documentation" is generally referring to it the infra.

Comment thread Doc/library/math.rst
returns ``(0.0, 0)``, otherwise ``0.5 <= abs(m) < 1``. This is used to "pick
apart" the internal representation of a float in a portable way.
Return the mantissa and exponent of *x* as the pair ``(m, e)``. *m* is a
float and *e* is an integer such that ``x == m * 2**e`` exactly. If *x*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worded a little oddly, since this seems to allow nan == nan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants