summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2022-12-24 20:09:31 (GMT)
committerGitHub <noreply@github.com>2022-12-24 20:09:31 (GMT)
commit2e1a9ce9890aba748a518a39d01d1ea6d623d0d9 (patch)
treef3b26f8e3be699c5509cac516df7a6276678c62f /Doc
parentf5b7b19bf10724d831285fb04e00f763838bd555 (diff)
downloadcpython-2e1a9ce9890aba748a518a39d01d1ea6d623d0d9.zip
cpython-2e1a9ce9890aba748a518a39d01d1ea6d623d0d9.tar.gz
cpython-2e1a9ce9890aba748a518a39d01d1ea6d623d0d9.tar.bz2
gh-100428: Make float documentation more accurate (#100437)
Previously, the grammar did not accept `float("10")`. Also implement mdickinson's suggestion of removing the indirection.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functions.rst21
1 files changed, 12 insertions, 9 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 817c1f8..2e98825 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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