I came across a problem where program added a float value to a long variable and result got completely wrong:
float toadd = 30548.0f;
long x1 = 1578726070000L;
long x1old= x1;
x1 += toadd;
Log.d("TEST", "X1=" + x1old + " X1+=" + x1 + " Added:" + toadd + " Delta=" + (x1 - x1old));
The Logcat showed then:
TEST: X1=1578726070000 X1+=1578726064128 Added:30548.0 Delta=-5872
I know that mixing float and long is tricky and should be avoided, but still, how comes that adding a value actually made the receiving variable decrease, and with a 'random' figure on top?