scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
401 stars 67 forks source link

Some exotic float codes representing negative zero converted to positive zero. #333

Closed scott-griffiths closed 2 months ago

scott-griffiths commented 2 months ago

Of course positive and negative zero are equal, but for types that support them both the bit representations obviously aren't

Here we set a to be the representation for -0.0 in a 6-bit MXFP format, then convert it to a Python float and back again. It should survive the round trip but doesn't:

>>> a = bitstring.BitArray('0b100000')
>>> a.e3m2mxfp = a.e3m2mxfp
>>> a
BitArray('0b000000')