Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-100428: Make float documentation more accurate #100437

Merged
merged 8 commits into from
Dec 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -650,20 +650,23 @@ are always available. They are listed here in alphabetical order.
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
produced. The argument may also be a string representing a NaN
(not-a-number), or positive or negative infinity. More precisely, the
input must conform to the following grammar after leading and trailing
whitespace characters are removed:
input must conform to the ``floatvalue`` production rule in the following
grammar, after leading and trailing whitespace characters are removed:

.. productionlist:: float
sign: "+" | "-"
infinity: "Infinity" | "inf"
nan: "nan"
numeric_value: `floatnumber` | `infinity` | `nan`
numeric_string: [`sign`] `numeric_value`

Here ``floatnumber`` is the form of a Python floating-point literal,
described in :ref:`floating`. Case is not significant, so, for example,
"inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for
positive infinity.
digitpart: `digit` (["_"] `digit`)*
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
exponent: ("e" | "E") ["+" | "-"] `digitpart`
floatnumber: number [`exponent`]
floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)

Here ``digit`` is a Unicode decimal digit (character in the Unicode general
category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
"INFINITY", and "iNfINity" are all acceptable spellings for positive
infinity.

Otherwise, if the argument is an integer or a floating point number, a
floating point number with the same value (within Python's floating point
Expand Down