C, big numbers and storing them

This is a discussion on C, big numbers and storing them within the C Programming forums, part of the General Programming Boards category; Originally Posted by Wiretron do you mind explaing how this works? surely ((a/b)*b) cancels down to (a), or does this ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Wiretron View Post
    do you mind explaing how this works?

    surely ((a/b)*b) cancels down to (a), or does this work by getting rid of any decimal places when calculating (a/b) ?

    thx
    As mike_g points out, it does a % b.

    If we assume that you are talking of integer math [which is how I understood your original question to be] then the result of (a/b) is the nearest WHOLE number that a can be divided by b, so 7/3 would give 2. If we then multiply that by b we get 6, and 7-6 is 1. 7 % 3 should also give 1.

    You may have to do more things to deal with signs and such, because I'm not sure what the spec says about a % b when one or both numbers are negative - as to what the "correct" mathematical behaviour is, I'm not quite sure. But for exampel negative a divided by negative b would make a positive number. Say we want -7 % -3:
    -7 / -3 = 2
    2 * -3 = -6
    -7 - -6 = -13
    That's not the answer we wanted - as modulo/remainder numbers should definitely ALWAYS be smaller [in absolute terms] than the b part .

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    ah k thx thats helped a lot

    the spec says dont worry about negatives

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    are there any efficient ways of dividing two numbers together?

    I have a big number and I'm trying to divide it into a very big number. i tried adding the smaller number to itself over and over and again until it was as big as the other number but this is ridiculously slow.

    thx

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    Quote Originally Posted by Wiretron View Post
    are there any efficient ways of dividing two numbers together?

    I have a big number and I'm trying to divide it into a very big number. i tried adding the smaller number to itself over and over and again until it was as big as the other number but this is ridiculously slow.

    thx
    actually dont worry about this, solved it

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Floating-Point Numbers
    By MindLess in forum C Programming
    Replies: 4
    Last Post: 06-24-2007, 11:45 PM
  2. Storing large numbers as an array
    By Rush152 in forum C Programming
    Replies: 9
    Last Post: 05-19-2006, 11:51 PM
  3. Reading all the numbes from a file and storing in an array
    By derek tims in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2006, 03:01 PM
  4. Storing and printing matrices
    By stevedawg85 in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2006, 07:57 AM
  5. storing numbers
    By kurz7 in forum C Programming
    Replies: 5
    Last Post: 01-16-2003, 07:49 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21