There was always a problem with mixing signed and unsigned variables in expressions (such practices were even forbidden in old mB). Note, that in version 3.8, where left-side of assignment decided the type with which partial expression evaluation was done, there'd be calculation error in statement identical to yours but with left-side of type Longword.
Version 4.0 is the first where an attempt at solving this issue was made (BTW, there's a chapter on expression evaluation in Help, now) - apparently it's not perfect yet, but the general rule about expression evaluation holds (expression evaluation is performed at the level of highest-type variable, or one step higher, if necessary - in your expression highest type is Word and evaluation is done on Longword level). Ideally, presence of any signed operand should force Longint as evaluation level, but at the moment it works only with highest type of variable.
In other words, your statement will work properly with explicit typecasting
Code: Select all
Vbatt_long = Elev_z - Longint(Elev_n - Elev_z) * Elev div 180
or
Code: Select all
Vbatt_long = Elev_z - Integer(Elev_n - Elev_z) * Elev div 180
or if you simply declare Elev as Integer.
Note, that with new evaluation rules introduced in v 4.0, the following will work properly
Code: Select all
Elev_pos = Elev_z - Integer(Elev_n - Elev_z) * Elev div 180
i.e. right side will be evaluated using highest necessary type and only then implicitely typecast to left-side variable type. It's definitely an advantage over previous versions, though I regard as most advantageus the fact that one may now better optimise code size (though it may require explicit typecasting).