remember, floating point arithmetic can be tricky, and it's always a good idea to be aware of its pitfalls. This is not a bug in Python or NumPy, but it is rather the nature of floating point numbers and the arithmetic operations that work on them.
The behavior you're watching is due to the contrasts in accuracy between diverse floating point sorts.
The term "drifting point" alludes to the way these numbers are spoken to inside. The subtle elements are very specialized, but the key point is that these numbers are spoken to employing a settled number of bits, and the more bits you have, got the more exactness you get.
Diverse sorts of floats in Python (or in libraries like NumPy) such as float16, float32, and float64 allude to floating point numbers that utilize 16, 32, and 64 bits separately.
A float64 (moreover known as "twofold exactness drift") has higher exactness and a bigger run than float32 ("single accuracy drift"), which in turn has higher exactness and larger range than float16 ("half accuracy float").
So, after you perform the same calculation utilizing different float sorts, you'll get somewhat diverse comes about due to these contrasts in exactness. Typically a common issue in numerical computations and it's something to be mindful of.
It's imperative to select the correct sort of float for your particular utilize case. In general, float64 could be a great default choice, since it offers a great adjust between accuracy and memory utilization. But on the off chance that you're working with exceptionally expansive datasets and memory utilization could be a concern, or on the off chance that you're performing computations on a GPU that underpins float32 or float16 computations, at that point it might make sense to utilize a lower-precision drift sort.
here is a little code to show you why
here is a little code to show you why :
import numpy as np
a1 = np.float16(226.72560000000001)
a2 = np.float16(0.2856000000000165)
b = np.float16(1.02)
a3= float(226.72560000000001)
a4 = float(0.2856000000000165)
b1 = float(1.02)
print((a3 - a4) // b1)
print((a1 - a2) // b)
print(np.floor((a3 - a4) / b1))
print(np.floor((a1 - a2) / b))
output :
221.0
222.0
222.0
222.0
You can change the type of float to see how it is affecting the result.