Results 1 to 9 of 9

Thread: Is there a difference?

  1. #1
    Guest

    Question

    Is there a difference for division when you use "/" or "\"?

  2. #2
    Guest
    The \ returns an Integer, whereas the / returns a floating-point.

  3. #3
    Guest

    Question

    yes there is, but what exactly do you mean? those 2 chars use to show up here and there in the IT world.

  4. #4
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    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

  5. #5
    Guest
    Originally posted by Megatron / floating-point
    What do you mean when you say that?

  6. #6
    Guest
    It means that there will be decimals at the end.

    Code:
    45 \ 6 = 7
    45 / 6 = 7.5
    Get what I mean?

  7. #7
    Guest
    Yup, I understand. It's like this:

    Code:
    45 \ 6 = 7 = (rounded)
    45 / 6 = 7.5 = (exact)

  8. #8
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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!)

  9. #9
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    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
  •  



Click Here to Expand Forum to Full Width