I know that similar precision questions have been asked here however I am reading a code of a project that is doing an exact equality comparison among floats and is puzzling me.
Assume that x1
and x2
are of type numpy.ndarray
and of dtype np.float32
. These two variables have been computed by the same code executed on the same data but x1
has been computed by one machine and x2
by another (this is done on an AWS cluster which communicates with MPI).
Then the values are compared as follows
numpy.array_equal(x1, x2)
Hence, exact equality (no tolerance) is crucial for this program to work and it seems to work fine. This is confusing me. How can one compare two np.float32
computed on different machines and face no precision issues? When can these two (or more) floats can be equal?