|
-
Aug 3rd, 2010, 10:40 PM
#1
Thread Starter
Fanatic Member
Order of operations?
Does vb6 follow the order of operations? (parenthesizes, exponents, multiplication, division, addition, subtraction)
-
Aug 3rd, 2010, 10:56 PM
#2
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
-
Aug 3rd, 2010, 11:00 PM
#3
Thread Starter
Fanatic Member
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?
-
Aug 4th, 2010, 03:25 AM
#4
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
-
Aug 4th, 2010, 03:26 AM
#5
Addicted Member
Re: Order of operations?
 Originally Posted by Gamemaster1494
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:
MsgBox (1 / 2)
MsgBox (1 \ 2)
Regards
Veena
-
Aug 4th, 2010, 07:00 AM
#6
Re: Order of operations?
You also get Remainder division which gives the remainder. you can use the Mod method for this, for example :
Will give me 1
and
Will give me 2
VB.NET MVP 2008 - Present
-
Aug 4th, 2010, 07:20 AM
#7
Re: Order of operations?
 Originally Posted by Ellis Dee
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
-
Aug 4th, 2010, 01:13 PM
#8
Re: Order of operations?
Agreed. You can't use it when precision is required. You should use it everywhere else.
-
Aug 4th, 2010, 01:26 PM
#9
Thread Starter
Fanatic Member
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. =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|