[Python-ideas] Adding a half-float (16-bit) type to PEP 3118 (and possibly the struct module?)

Eli Stevens (Gmail) wickedgrey at gmail.com
Thu Mar 31 02:32:13 CEST 2011

On Wed, Mar 30, 2011 at 5:06 PM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> I think the struct module addition for float16 could be handled separately and much more easily (since a half would fit in a double, but a long long double won't).

Okay, if no other objections get raised, I'll open a new issue for it
(probably sometime tomorrow).

> If you need something for today, it's not hard to write pure python code using struct to read in an int16 and then do the bit manipulations to pick apart the sign, exponent, and mantissa to create the float value.

My particular use case focuses on getting float16 data from numpy
(which handles the bit fiddling already) to be exposed in cython
(which doesn't ATM, and can't know to do so without a specific float16
data format type).  Step one of that is to update the spec to include
a float16 type, either by changing PEP 3118, or adding it to the
struct module (which is referenced by the PEP).  Once that happens, I
think there's a valid case to be made for numpy to export the float16
via the buffer interface, and a decent shot at getting some special
case code added to cython.  I don't need any CPython code changes for
my use case, I don't think.

> I don't follow what your issue is?  Can you check-out a copy of the current Hg repository and build your patch against the default branch?

Sorry, I'm juggling three different threads on this topic
(python-ideas, cython-users, numpy-discussion), and am doing a poor
job of keeping the contexts sorted out.  :)

Yes, I will try and compile/test CPython and build a patch for
_struct.c from the current repo.


More information about the Python-ideas mailing list