Multiplication/Division problem with big numbers

Hey folks,
Recently I wrote a program to the athematic operations with large numbers traditionally known as bigint.


Last edited on
any suggestions folks?
I'm no expert, but I think there's probably a problem with checking the relational operators "!=" and ">=" for the Bigint class.
closed account (D80DSL3A)
I agree with fg109. It seems like the repeated addition/subtraction methods should work.
EDIT: I would expect that your method for the big value case would never return a result. With num2 = 8528587375585 that's about 85 trillion iterations!

I also agree that a different algorithm for * and / would be useful.

The + operation as you have it works by implementing the same method one would use to make the calculation by hand, which you already know because you intentionally wrote the + function to do that.

You can write functions which implement the by hand methods for multiplying or dividing two numbers also.
I found writing the function to do long division a bit tricky but I got it working.
Since the operands are integers you might want to implement both / (quotient) and % (remainder) operators, just like "real" integers. Both of these results are found by the long division function. Write the operators to perform the division then return either the quotient or the remainder.
Last edited on
Well I heard shifting will solve the problem with very big second operand in multiplication and in division with big results.
Last edited on
Topic archived. No new replies allowed.