Android Question rules of precedence

makeed0

New Member
What are the rules of precedence when dealing with built-in mathematical functions such as Sin, floor, and Ceil?
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
Can you give an example where you think that an order of precedence for functions such as these is necessary? Rules of precedence are needed for something like the following, involving arithmetic operators, not functions . . .

A = X + Y * Z

You have to know the rules to realise that this (normally) means X + (Y * Z) rather that (X + Y) * Z. Note that the "rules of parentheses" are much less ambiguous - terms within parentheses are evaluated first and from inside to outside and left to right. Since the examples that you have given are all functions rather than operators, and so always require parentheses, then, it seems to me, that the rules of parentheses will always remove any ambiguity.

For instance . . .

sin(max(a, b))

. . . is not at all ambiguous. I am trying to think of a situation where this would not apply.
 
Upvote 0
Top