Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ are always available. They are listed here in alphabetical order.
single: NaN
single: Infinity

Return a floating-point number constructed from a number or a string.
Return a floating-point number constructed from a number, a string, or a bytes-like object.

Examples:

Expand All @@ -794,6 +794,10 @@ are always available. They are listed here in alphabetical order.
1000000.0
>>> float('-Infinity')
-inf
>>> float(b'3.2e2')
320.0
>>> float(bytearray(b'-2.5'))
-2.5

If the argument is a string, it should contain a decimal number, optionally
preceded by a sign, and optionally embedded in whitespace. The optional
Expand All @@ -819,6 +823,9 @@ are always available. They are listed here in alphabetical order.
Case is not significant, so, for example, "inf", "Inf", "INFINITY", and
"iNfINity" are all acceptable spellings for positive infinity.

If the argument is a bytes-like object, it must contain only ASCII characters
that conform to the :token:`~float:floatvalue` rule.

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
precision) is returned. If the argument is outside the range of a Python
Expand Down
4 changes: 2 additions & 2 deletions Objects/clinic/floatobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,12 +1560,12 @@ float.__new__ as float_new
x: object(c_default="NULL") = 0
/

Convert a string or number to a floating-point number, if possible.
Convert a string, number, or bytes-like object to a float, if possible.
Comment thread
skirpichev marked this conversation as resolved.
[clinic start generated code]*/

static PyObject *
float_new_impl(PyTypeObject *type, PyObject *x)
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=55909f888aa0c8a6]*/
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=27eb1f7c62226a39]*/
{
if (type != &PyFloat_Type) {
if (x == NULL) {
Expand Down
Loading