Results 1 to 9 of 9

Thread: Order of operations?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Order of operations?

    Does vb6 follow the order of operations? (parenthesizes, exponents, multiplication, division, addition, subtraction)
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Order of operations?

    For the most part, yes. As a general rule I would go with parentheses.

    An example where it breaks down is the "\" integer-division operator. You'd think it would have the same OOO as regular division, but it does not:
    Code:
    ?10/2*5
     25 
    ?10\2*5
     1

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Order of operations?

    so since \ is integer division, what is /? just regular old division? even if i did 1/2 or 1\2, would it still show .5?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  4. #4
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Order of operations?

    / is actual division. 1/2 = 0.5
    \ is integer division, which only returns integers. 1/2 = 0

    \ is orders of magnitude faster than / because division is a very expensive operation. You should use \ over / everywhere possible. It doesn't actually do division, but instead simply counts the number of times the denominator goes into the numerator.

    Examples:
    10 \ 2 = 5
    10 \ 3 = 3
    10 \ 4 = 2

  5. #5
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: Order of operations?

    Quote Originally Posted by Gamemaster1494 View Post
    so since \ is integer division, what is /? just regular old division? even if i did 1/2 or 1\2, would it still show .5?
    Test it Yourself.. far easier than waiting for someone to reply..
    vb Code:
    1. MsgBox (1 / 2)
    2. MsgBox (1 \ 2)

    Regards
    Veena

  6. #6
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Order of operations?

    You also get Remainder division which gives the remainder. you can use the Mod method for this, for example :

    Code:
    8 Mod 7
    Will give me 1

    and

    Code:
    6 Mod 4
    Will give me 2
    VB.NET MVP 2008 - Present

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Order of operations?

    Quote Originally Posted by Ellis Dee View Post
    You should use \ over / everywhere possible.
    "May need to" would arguably be more appropriate to say instead - otherwise you may lose precision in many cases like this wich may be crucial:

    10 \ 6 = 1
    10 / 6 = 1.66666666666667

  8. #8
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Order of operations?

    Agreed. You can't use it when precision is required. You should use it everywhere else.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Order of operations?

    Darn. Now i have to go threw and change the signs. Thank god for Find and replace! Thanks everyone! I'll use / from now on. =)
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

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