Math bug??

When I do

float y = analogRead(A0);

y *= 5 / 1024;

y will be 0,00 nomather what analogRead returns.

but this:

y = y * 5 / 1024;
This actually returns the correct value.

You would think that y *= x would be the same as y = y * x but this is not true when x is a fracture.
Is this normal in C as well, or is this just arduino language??

kind regards,

BK

Not a bug; integer math is tripping you up. Try:

y *= 5.0 / 1024.0;

y*=5 / 1024 is NOT the same as y = y * 5 / 1024

y*=5 / 1024 is the same as y=y*(5/1024) which is clearly 0. Look up operator presedence and the order expression evaluation in C/C++.

The Arduinos use C/C++

Mark