[Python-ideas] float('∞')=float('inf')

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Jul 15 12:26:43 CEST 2013


On 12 July 2013 13:36, Zaur Shibzukhov <szport at gmail.com> wrote:
>
> Is it good idea to allow
> float('∞') to be float('inf') in python?

I don't think so as my preference is for Python to stick to IEEE 754
as closely as possible.

Section 5.12.1 of IEEE 754-2008 says
'''
Conversion of an infinity in a supported format to an external
character sequence shall produce a language defined one of “inf” or
“infinity” or a sequence that is equivalent except for case (e.g.,
“Infinity” or “INF”), with a preceding minus sign if the input is
negative. Whether the conversion produces a preceding plus sign if the
input is positive is language-defined.

Conversion of external character sequences “inf” and “infinity”
(regardless of case) with an optional preceding sign, to a supported
floating-point format shall produce an infinity (with the same sign as
the input).
'''

This does not seem to prohibit accepting other strings for infinity
but it does explicitly define a set of textual representations for
infinity. I don't think Python's float <-> str conversions should
accept (or emit) any other strings for infinity.

Since I was looking at the standard I was also interested to see what
is says about non-ascii decimal digits (as accepted by Python 3).
Immediately above this in section 5.12 it says
'''
Issues of character codes (ASCII, Unicode, etc.) are not defined by
this standard.
'''

My interpretation of that is that Python's current behaviour is
conforming but that it would also be conforming if it didn't accept
non-ascii decimal digits.


Oscar


More information about the Python-ideas mailing list