# 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. Originally Posted by Wiretron
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

2. ah k thx thats helped a lot

the spec says dont worry about negatives

3. 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. Originally Posted by Wiretron
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

Page 2 of 2 First 12