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

Raymond Hettinger raymond.hettinger at gmail.com
Thu Mar 31 02:06:16 CEST 2011

On Mar 30, 2011, at 4:34 PM, Eli Stevens (Gmail) wrote:

> On Wed, Mar 30, 2011 at 3:03 PM, Raymond Hettinger
> <raymond.hettinger at gmail.com> wrote:
>> I would support adding float16 to the struct module.
>> It's a well defined format so we might as well provide an accessor.
>> Just open a feature request for it.
> This seems like a simple solution, however:
> On Wed, Mar 30, 2011 at 1:24 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> If this were added to the PEP, it would be included in
>> http://bugs.python.org/issue3132

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).

> Also, am I correct in my understanding that any code changes to
> _struct.c, etc. would not show up in a production release before 3.3?

Yes, that's right.

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.

> I'm based out of a strictly 2.7 shop, so if I'm going to need to
> develop patches, I'll have to make sure I have some place to test
> things (for our purposes, we just need a spec that numpy and cython
> can standardize on, but if a patch to the struct module is what it's
> going to take to make that happen, I'll give it a shot :).

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?


More information about the Python-ideas mailing list