pint
pint copied to clipboard
converting between units and equality
pint 0.24.3
I would expect that when converting from say 1 lb
to 16 oz
and then back to lb
would be equivalent, but it doesn't seem to be the case:
In [21]: from pint import UnitRegistry
In [22]: ureg = UnitRegistry()
In [23]: (1 * ureg.lb).to(ureg.oz)
Out[23]: <Quantity(16.0, 'ounce')>
In [24]: (1 * ureg.lb).to(ureg.oz) == 16 * ureg.oz
Out[24]: False
In [25]: (1 * ureg.lb).to(ureg.oz) == 16.0 * ureg.oz
Out[25]: False
It appears that it might have to do with floating point precision:
In [28]: (1 * ureg.lb).to(ureg.oz).magnitude
Out[28]: 16.000000000000004
Is this the expected behavior?