P positrom2 Active Member Licensed User Longtime User Dec 20, 2016 #1 How a composite arithmetic expression like A=(C-D)/(e+f) is evaluated in case the numbers are of mixed types? If C is float (Double) and D,A are int, which type will be the intermediate C-D? If C-D=.1, and e+f=.1, A=0 or A=1?
How a composite arithmetic expression like A=(C-D)/(e+f) is evaluated in case the numbers are of mixed types? If C is float (Double) and D,A are int, which type will be the intermediate C-D? If C-D=.1, and e+f=.1, A=0 or A=1?
Erel B4X founder Staff member Licensed User Longtime User Dec 21, 2016 #2 If C is double then D will also be converted to a double. positrom2 said: If C-D=.1, and e+f=.1, A=0 or A=1? Click to expand... It should be 1. However it is safer to use Round: Code: Copy A = Round(...) Otherwise a small rounding error can cause it to be 0 instead of 1. Remember that decimal values cannot be accurately represented in a floating point value. Upvote 0
If C is double then D will also be converted to a double. positrom2 said: If C-D=.1, and e+f=.1, A=0 or A=1? Click to expand... It should be 1. However it is safer to use Round: Code: Copy A = Round(...) Otherwise a small rounding error can cause it to be 0 instead of 1. Remember that decimal values cannot be accurately represented in a floating point value.
P positrom2 Active Member Licensed User Longtime User Dec 21, 2016 #3 Erel said: Otherwise a small rounding error can cause it to be 0 instead of 1. Click to expand... Thanks, so that might have been the problem in my "attempt" to fit the BMP280 readings like 123456.89 into the OLED int 0-63 range... I am coming from another Basic dialect (Bascom) that allows just one operation per line. In that case, it is more obvious what happens though quite tedious to disentagle a more composite equation. Upvote 0
Erel said: Otherwise a small rounding error can cause it to be 0 instead of 1. Click to expand... Thanks, so that might have been the problem in my "attempt" to fit the BMP280 readings like 123456.89 into the OLED int 0-63 range... I am coming from another Basic dialect (Bascom) that allows just one operation per line. In that case, it is more obvious what happens though quite tedious to disentagle a more composite equation.