Results 1 to 7 of 7

Thread: Operator Presedence

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728
    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
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Are "And" & "or" same level?

    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.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ok a revision:

    mathematical:
    ^
    -
    *,/
    \
    Mod
    +-

    Comparation:
    =
    <>
    <
    >
    <=
    >=

    Logical:
    not
    And
    Or
    Xor
    Eqv
    Imp

    Note, this is at least how vb orders operators precedence.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Thanks

    Thanks for the response. I have the problem sorted now.

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width