PDA

Click to See Complete Forum and Search --> : Operator Presedence


[Digital-X-Treme]
Mar 4th, 2001, 12:11 PM
I have a few questions on operator presedence that i need confirming.

I have the following operators. The lower the number after the operator, the higher the presedence.

Equals: "=" 0
Is equal to: "==" 1
Not equal to: "!=" 1
Greater than or equal to: ">=" 1
Less than or equal to: "<=" 1
Less than: "<" 1
More than: ">" 1
Power: "^" 2
Multiply: "*" 3
Division: "/" 3
Integer Division: "\" 3
Mod "%" 3
And "&" 4
Or "|" 4
Addition "+" 4
Minus "-" 4


What i need to know is this.
1. Is the 'integer division operator' (\) of equal presedence to "/" and "*"? (as i assume it is)

2. I am assuming that '&' and "|" are of the same presedence as "+" and "-", and that "%" is of the same presedence as "/" and "*". Is this correct?

1. Basically, are they in the correct order of presedence? :)

Any contributions appreciated. Thanks in advance.

Later

Guv
Mar 4th, 2001, 04:19 PM
I thought that "And" & "Or" had a different precedence, but I am not at all sure. The others seem correct.

There must be literature on this subject. I would advise checking the Web or your your local library.

kedaman
Mar 4th, 2001, 06:56 PM
AND and OR have same precedence in logics, but in vb AND has a higher precedence, haven't tested other languages of this. Also all mathematical operators are higher than comparation operators, which in turn are higher than all logical operators.

INTEGER DIVISION IS LOWER THAN FLOATIN PTDIVISION AND MULTIPLICATION, this caused me quite much trouble, until i discovered it was this way.

For comparations:
equality is strongest = (==)
next comes <> (!=)
<
>
<=
>=
For logical operators also, Implication is lower than Equivalence, which is very odd, Xor which doesn't appear in logics, is lower than Or but higher than Eqv and Imp.

And one more thing for mathematical operators, -X that is negation operator, not substraction, is higher than multiplication and lower than exponentation

kedaman
Mar 4th, 2001, 07:04 PM
ok a revision:

mathematical:
^
-
*,/
\
Mod
+-

Comparation:
=
<>
<
>
<=
>=

Logical:
not
And
Or
Xor
Eqv
Imp

Note, this is at least how vb orders operators precedence.

HarryW
Mar 4th, 2001, 08:49 PM
In boolean algebra, A.B+C where . is 'and', and + is 'or' is equivalent to (A.B)+C so err... basically what I am saying is AND is higher precendence than OR in logic too.

kedaman
Mar 5th, 2001, 09:59 AM
Hmm, maybe there are different schemes for different purposes, here's from our logic course:
x:=e (textual substitution)
. (functional application)
unary prefix operators: +,-,¬,#,~,P
**
.,/,%, mod, gcd
+,- (°,È,Ç,Ä,×) symbol fonts
(¯*) symbols again
#
<|, |>, ^
=, <, > (Î,Ì,Í,É,Ê,ç) symbols (*)
and, or (*)
=>, <=
eqv (*)


the cases with (*) may have a slash trough them indicating negation.

[Digital-X-Treme]
Mar 5th, 2001, 02:35 PM
Thanks for the response. I have the problem sorted now.

Later