I realize the np.islcose() function can be used to safely check floating point numbers for equality. What's tripping me up at the moment, though, is that I get varied results from using the standard <= operator. For example:
add_to = 0.05
value64 = np.float64(0.3) + add_to*4
value32 = np.float32(0.3) + add_to*4
threshold = 0.5
print('is close?')
print(np.isclose(value64, threshold))
print(np.isclose(value32, threshold))
print('is less than or equals to?')
print(value64 <= threshold)
print(value32 <= threshold)
Gives me
is close?
True
True
is less than or equals to?
True
False
Does anyone have a sensible workaround for this? I thought one option might be overload the python comparison operators for numpy floating points, and (within that function) round both floats up to, say, their 8th decimal place. But this is in a context where speed is somewhat important, and that feels a bit cumbersome.
Thanks in advance for any help!