[issue11734] Add half-float (16-bit) support to struct module

Paul Hoffman report at bugs.python.org
Tue Apr 23 18:23:52 CEST 2013


Paul Hoffman added the comment:

Mark:

>I don't see how math.isnan or math.isinf would be affected: we're not proposing to make a float16 Python type, so math.isnan would never encounter a float16 value.

I was assuming that this proposal would also make this part of class 'float' just like the other floats returned from struct. Otherwise, you will get goofy cases where someone has to special-case what they get from struct.

import math, struct
FullInfinityAsInt = 0x7f800000
ThisFloat = (struct.unpack("f", struct.pack("I", FullInfinityAsInt)))[0]
print("The type is " + str(type(ThisFloat)))
if math.isinf(ThisFloat):
	print("This is an infiniity")
else:
	print("This is not an infinity")

This should work similarly for the new half-precision, I would think.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11734>
_______________________________________


More information about the Python-bugs-list mailing list