This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: float('∞') returns 8.0
Type: behavior Stage: resolved
Components: Unicode Versions: Python 3.5
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: David Howlett, ashwch, eryksun, ezio.melotti, vstinner
Priority: normal Keywords:

Created on 2016-06-29 11:26 by David Howlett, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg269475 - (view) Author: David Howlett (David Howlett) Date: 2016-06-29 11:26
float('inf') returns a float with a value of inf
float('∞') returns a float with a value of 8.0

I can't think of any justification for returning 8.0 other then ∞ looks like an 8 turned sideways. I believe float('∞') should return inf.
msg269477 - (view) Author: Ashwini Chaudhary (ashwch) * Date: 2016-06-29 11:43
float('∞') raised ValueError as expected: ValueError: could not convert string to float: '∞'

I am not sure how you ended up with 8.0.
msg269478 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-06-29 11:47
There's something wrong with however you're testing this. 

    >>> s = '\N{infinity}'
    >>> s == '∞' == '\u221e'
    True

'∞' isn't numeric. It's a math symbol (Sm):

    >>> unicodedata.category(s)
    'Sm'
    >>> s.isdecimal()
    False
    >>> s.isdigit()
    False

So float('∞') should raise a ValueError:

    >>> float(s)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: '∞'
msg269480 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-06-29 12:06
On Windows, the ∞ character (U+221E) is replaced with the letter 8 (U+0038) by the WideCharToMultiByte() function for most code pages:
http://unicodebook.readthedocs.io/operating_systems.html#encode-and-decode-functions

Can you please describe how and where you typed the ∞ character? Are you testing on Windows? What is your Python version?
msg269484 - (view) Author: David Howlett (David Howlett) Date: 2016-06-29 13:19
I am using python 3.5 in a REPL in an IDE called Komodo running on Windows.

After reading your comments I wrote the following python file:

try:
    x = float('∞')
except ValueError:
    print('Value error was correctly thrown')

This throws a ValueError as you describe. I get the following behaviour in powershell and cmd.exe:

>>> float('\u221e')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '\u221e'

In the Komodo REPL I see the following behaviour:

>>> '∞'
'8'
>>> '\u221e'
'\u221e'

I now believe the issue is with how Komodo reads in characters from its REPL.

In the course of testing I also found out that the REPL in Komodo suffers and internal fault whenever it tries to print '∞' in a debug message.

Unless someone objects I will close this issue in the Python bug tracker and open a new issue in the Komodo bug tracker.
msg269485 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-06-29 13:28
"""
In the Komodo REPL I see the following behaviour:

>>> '∞'
'8'
"""

Ok, it's now obvious that the issue comes from Komodo REPL, not from Python.
msg269504 - (view) Author: David Howlett (David Howlett) Date: 2016-06-29 14:37
I am sorry about misattributing this bug and wasting your time.

I have opened two new bugs against Komodo:

https://github.com/Komodo/KomodoEdit/issues/1760
https://github.com/Komodo/KomodoEdit/issues/1759

They are looking into it.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71599
2016-06-29 14:37:13David Howlettsetmessages: + msg269504
2016-06-29 13:28:05vstinnersetmessages: + msg269485
2016-06-29 13:23:03eryksunsetstatus: open -> closed
resolution: third party
stage: resolved
2016-06-29 13:19:50David Howlettsetmessages: + msg269484
2016-06-29 12:06:10vstinnersetmessages: + msg269480
2016-06-29 11:47:28eryksunsetnosy: + eryksun
messages: + msg269478
2016-06-29 11:43:54ashwchsetnosy: + ashwch
messages: + msg269477
2016-06-29 11:26:37David Howlettcreate