Does vb6 follow the order of operations? (parenthesizes, exponents, multiplication, division, addition, subtraction)
Printable View
Does vb6 follow the order of operations? (parenthesizes, exponents, multiplication, division, addition, subtraction)
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
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?
/ 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
You also get Remainder division which gives the remainder. you can use the Mod method for this, for example :
Will give me 1Code:8 Mod 7
and
Will give me 2Code:6 Mod 4
Agreed. You can't use it when precision is required. You should use it everywhere else.
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. =)