|
-
May 31st, 2000, 06:06 AM
#1
Is there a difference for division when you use "/" or "\"?
-
May 31st, 2000, 06:15 AM
#2
The \ returns an Integer, whereas the / returns a floating-point.
-
May 31st, 2000, 06:17 AM
#3
yes there is, but what exactly do you mean? those 2 chars use to show up here and there in the IT world.
-
May 31st, 2000, 06:23 AM
#4
Addicted Member
Yes Matthew, there is a difference.
The backslash must return an integer and it rounds numbers.
e.g 2.5 \ 1.5 rounds to 3\2 or 1.5 which is then rounded to 1. In other words it returns how many 1.5's are in 2.5 in whole numbers, answer - only 1.
I hope I explained that right, but that's basically how it works
GRAHAM
-
May 31st, 2000, 06:24 AM
#5
Originally posted by Megatron / floating-point
What do you mean when you say that?
-
May 31st, 2000, 06:27 AM
#6
It means that there will be decimals at the end.
Code:
45 \ 6 = 7
45 / 6 = 7.5
Get what I mean?
-
May 31st, 2000, 07:13 AM
#7
Yup, I understand. It's like this:
Code:
45 \ 6 = 7 = (rounded)
45 / 6 = 7.5 = (exact)
-
May 31st, 2000, 07:48 AM
#8
Fanatic Member
but the \ operator is HEAPS quicker.
if you have a loop with intensive math, you're better off multiplying your 3 dec vars by 1000, holding them in Long's and using the \ type. the overhead to calculate floating points, singles and doubles is very high.
and it's not rounded!
100 goes into 99 zero times, it never rounds up.
99 / 100 = 0.99
99 \ 100 = 0
which is why it's faster, it doesn't calculate the modulus
[Edited by Paul282 on 05-31-2000 at 08:53 PM]
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
May 31st, 2000, 09:19 AM
#9
Hyperactive Member
There's a subtle point to what the good people here say relative to the / and \ operators. It's very easy to unwittingly declare an integer, long or byte datatype and then via VB's weak type-casting, waste a huge amount of CPU cycles doing floating-point arithmetic.
For example:
Code:
Dim X AS Integer
X = 7/3 ' bad kitty method
' processor does backflips to return 2.33333
' which is then type-cast to a result of 2
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
|