Is it possible to lose any fidelity or precision going from a numpy float32 to a python float (float64) back to a numpy float32?
I can’t seem to find a case where there is data lost but everyone around me is claiming that the world will end because there is data lost. I just need to find a document/example that proves that data is lost before I continue.
Any help pointing me in the right direction is appreciated.
Here is a typical use case I’m seeing:
def serialize(val):
# val is a np.float32
return val.astype(float)
def deserialize(msg):
return np.float32(msg)
message = '1.23456789'
outgoing = serialize(message)
incoming = deserialize(message)
If
xis a float32 thenfloat32(float64(x)) == x.The one exception being if
x = nanthennan != nan, althoughnan is nan, hence if you want to catch all you could use:.
You should take care: