[Python-Dev] [Python-checkins] r64424 - in python/trunk:Include/object.h Lib/test/test_sys.py Misc/NEWSObjects/intobject.c Objects/longobject.c Objects/typeobject.cPython/bltinmodule.c

Mark Dickinson dickinsm at gmail.com
Fri Jun 27 23:54:52 CEST 2008


On Fri, Jun 27, 2008 at 8:02 PM, Guido van Rossum <guido at python.org> wrote:
> Now that I've learned about the hex float format supported by C++ and
> Java, I wonder if it wouldn't be better to support conversion to and
> from that format and nothing else.
>
> E.g.
>
>>>> math.tohex(3.14)
> '0x1.91eb851eb851fp+1'
>>>> math.fromhex('0x1.91eb851eb851fp+1')
> 3.1400000000000001

This would certainly be enough for me, though I think there's still
some educational value in having binary output available.  But
that's just a matter of substituting a four-bit binary string for
each hexadecimal digit (or learning to read hexadecimal as
though it were binary).

In fromhex, what would be done with a string that gives more
hex digits than the machine precision can support?  An obvious
answer is just to round to the nearest float, but since part of the
point of hex floats is having a way to specify a given value
*exactly*, it might make more sense to raise an exception
rather than changing the value by rounding it.

Mark


More information about the Python-Dev mailing list