[SOLVED] Type of intermediate but non-stored variables - how does it work?

Yes, you do have to take care. By default on an 328P ( 8-bit processor ) all intermediate arithmetic is done with 16bit integer as long as none of the operands is long or float.
Your use case 3 should look like
b_output = (long)a_input * b_max / a_max;
to tell the compiler to use 32bit arithmetic. Then the result will be correct.
It doesn't matter which of the two operands is casted to long so this:
b_output = a_input * (long)b_max / a_max;
will work also.

1 Like