
Bar (Customer) asked a question.
Hello,
I am trying to enter a particular expression with parentheses into the MATH function, and when saved, the expression changes. Enough so, that that the expression is different and will not result in the correct output.
The entered expression is 4.6869 * (R7 ^ 2.0) + (14.8493 * R7) - 4.451. R7 is 2.842.
When "OK" is selected, the output is:
((4.6869 * (R7 ^ 2.0)) + (14.8493 * R7)) - 4.451. This Calculates as 4.6869 * (R7 ^ 2.0) because additional parentheses are added for some reason and any expression outside of the parentheses are ignored: (4.6869 * (2.842 ^ 2)= 37.85. Can someone explain?
More examples that will also not work:
4.6869 * R7 ^ 2.0 + 14.8493 * R7 - 4.451 yields "Integer Expression with Real Result" and then converts the expression to (4.6869 * R7) ^ ((2.0 + (14.8493 * R7)) - 4.451) which is also incorrect. Not sure why this expression would calculate as an integer as R7 is a real number, no?
4.6869 * (R7 ^ 2.0) + 14.8493 * R7 - 4.451 yields ((4.6869 * (R7 ^ 2.0)) + (14.8493 * R7)) - 4.451 which is also incorrect.
(4.6869 * (R7 ^ 2.0) + 14.8493 * R7 - 4.451) yields ((4.6869 * (R7 ^ 2.0)) + (14.8493 * R7)) - 4.451 which only calculates what is inside the first two parentheses again.
I think it's making that "correction" because of PEMDAS. If your goal is to solve it left to right, you'll have to code it differently.
I believe you want "...(R7**2)...". if you are trying to raise R7 to the power of 2.
Thanks. I see that now from the documentation. The ^ still seems to give the same answer, which is strange as it is a "Math Bit-wise XOR operator" but I did change it to **.
Still have the same issue with parentheses showing up unannounced and producing the wrong result though.
The operator precedence for every programming language is slightly different. If you are seeing the parentheses show up "different" than what you expect, that meant that your assumption of operator precedence was NOT what Do-more Designer supports.
Hence the reason why "regeneration" of the MATH expression places the parentheses in the Do-more operator precedence rules. If it's not what you expected, that's a good thing - it means you need to explicitly put the parentheses where you think they need to be (not some 7 level language spec operator precedence section).
Yeah, I just checked out Designer - it follows C++ rules for multiplication, division, and modulo
This will be an interesting exercise:
How should this be interpreted: 100 % 64 / 3 * 5?
((100 % 64) / 3) * 5
or
100 % (64 / (3 * 5))
Clue: it is C++ rules (probably C and Java and C# then also)
???
curious,
I entered:
Result: R6
Expression: 4.6869*(R7**2.0)+(14.8493*R7)-4.451
Same as you.
It then converted to:
Expression: ((4.6869 * (R7 ** 2.0)) + (14.8493 * R7)) - 4.451
Same as you.
But my result in R6 is 75.60664
Which I believe is the result you are looking for.
Is anything else in the program writing to R7? Or R6?