hi, i came across this fine code over at the Italian side of the forum.
it compiles (when u add setup and loop) but one line of code looks strange.
can someone decypher this?
dst = (0.5L*((float)analogRead( PIN_ST )))/10; //lettura in volt
17th line of code in the second code box, original poster is kokiua
0.5L ?
(float)analogRead(x) ?
float used in this way is not a function, it's a cast.
float(foo); // BAD - call float as if it is a function.
(float) foo; // GOOD - convert foo's value (presumably an int) to a floating-point value for the duration of this expression.
As to your other point, yes, the entire expression could be re-written as a cast-to-float divided by 20. There's presumably a belief that multiplying is a faster operation than division, but a decent compiler should do the best thing in any case.
That said, 0.5 * x / 10 may be more documentary code than x / 20 (those numbers look fairly magic either way, however).