[New-bugs-announce] [issue7028] hex function should work with floats

Josh Cogliati report at bugs.python.org
Thu Oct 1 04:51:53 CEST 2009

New submission from Josh Cogliati <jjcogliati-r1 at yahoo.com>:

The hex() builtin function only takes integers.  Also there is no way to
create a floating point number from a hexadecimal string.  However it
would often be useful to be able to see the hexadecimal version of an
float since this is an exact representation as compared to the decimal

I propose that the format 0xMantisaP0xBase2Exponent be used (but other
possibilities would be fine.  For example in this way 0.5 decimal would
be 0x1p-0x1 hex.  1.1 decimal would be 0x8cccccccccccdp-0x33 and pi
would be 0x3243f6a8885a3p-0x30

Attached are two functions I created to implement this.  If this would
be better as a PEP I will create one.  

This will cause a slight incompatibility, since now hex will throw an
exception if it is passed a float.

components: Library (Lib)
files: fhex.py
messages: 93389
nosy: jrincayc
severity: normal
status: open
title: hex function should work with floats
versions: Python 3.1
Added file: http://bugs.python.org/file15011/fhex.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list