Bug #12744

Careful - this may not evaluatie as you expect - use brackets.

Added by Evil_Echo about 5 years ago. Updated about 5 years ago.

Status:Feedback Start date:08/06/2010
Priority:Normal Due date:
Assignee:- % Done:


Target version:-
Affected Version:


_Quality = sqrt(_cost)/(1 + _accuracy);

It highlighted "sqrt(_cost)" as the culprit. _cost is scalar. Parentheses should be legitimate here to force ordering of evaluation.


Updated by sbsmac about 5 years ago

  • Status changed from New to Feedback

Actually the warning here is correct. The parentheses around _cost do nothing to associate it with sqrt - this would only be guaranteed if you wrote

(sqrt _cost)/(1+_accuracy)

Alternatively you may have intended

sqrt (_cost/(1+_accuracy))

In practice most arithmetic operators are evaluated from left to right so the code as written would have been evaluated as the first option but the warning is intended to highlight that the statement is potentially ambiguous.

Updated by sbsmac about 5 years ago

If nothing else, this does suggest that the warning message could be improved to make it clearer as to exactly what the warning is about!

Updated by Evil_Echo about 5 years ago

The evaluation order was intented to be the 1st one you cited.

Agree the parens around _cost were redundant - I'm a C coder of many decades and the style was just habit.

Still not sure it warranted a warning message - perhaps you are correct about clarifying that one.

Updated by sbsmac about 5 years ago

The reason for the warning message is that associativity depends quite a lot on the operators being used (there are some underlying rules but they are not necessarily obvious to your average coder). For example...

a select 2 +4 evaluates to (a select 2)+4

sin 45 +100 evaluates to (sin 45) + 100

sleep 10 + random 10 evaluates to sleep (10+random 10)

player setdir count [] +3 evaluates to player setdir ((count []) +3)

5 max 10 atan2 11 evaluates to 5 max (10 atan2 11)
5 atan2 10 max 11 evaluates to (5 atan2 10) max 11

Hence the recommendation/warning to use brackets where there is ambiguity.

Updated by Evil_Echo about 5 years ago

Could the wording be modified then? The term brackets is unfortunately vague.

Round brackets, aka parentheses - ()
Square brackets - []
Curly brackets, aka curlies, braces - {}

Updated by sbsmac about 5 years ago

Yes - I think this is a good suggestion. Ideally, the warning would point out that there are two possible interpretations and then allow the user to select which one was intended.

Also available in: Atom PDF