On 11/2/2010 6:11 AM, Hrvoje Niksic wrote:

1.1 .hex()
'0x1.199999999999ap+0'

Here it is immediately obvious that the final digit of the infinite
sequence "1.1999..." is rounded from 9 to a.  Printing the number with
any more digits would just reveal zeros, as expected.

Does anyone know why Python doesn't accept hex float literals in source
code?

Assuming that the parser would have no problem with them:
1. the format is relatively recent
2. you can write float.fromhex('<hex literal>')
3. it never occurred to anyone to do so
4. literals are values supplied by the programmer; hex float values are rare and when they do occur, they are usually the stored output of a previous .hex() in Python or similar in other languages.
5. too easy to confuse in quick reading with normal float literals
6. the format is a bit weird and too esoteric for most programmers; they should not be part of the basic syntax that everyone has to learn; someone who reads float.fromhex(something) can look it up.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to