Re: how to add two no. of 100 digits or more?



In article <1180511603.131286.56600@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Umesh <fraternitydisposal@xxxxxxxxx> wrote:

Is there any way by which i can do it? Thanks.

Yes. You do it the same way you would do it by hand on paper. The main
difference is that it might be more convenient to work in something
other than base 10, depending on exactly how you have the numbers
represented.

If *all* you need to do is add numbers, this is sufficient. It will be
easy to implement, and the time complexity will be O(N), where N is the
number of digits in the larger number, and that is the best you can do,
so no need to use an arbitrary precision library.

However, if you need to multiple or divide numbers with 100 digits or
more, then do as others have said, and find an arbitrary precision
library that looks good to you and use it. While you can reasonably
implement multiplication on your own following the common by-hand
algorithm, that's O(N^2) to multiply two N digit numbers, and that is
considerably slower than what you can do, but getting better involves
things not for the feint of heart. (I left subtraction out...it's not
really much different from addition, but you can blow it, so it can go
either way as to whether doing it yourself or using a library is best if
all you need is addition and subtraction).

See Knuth volume 2 for the details. (If possible, see all editions of
Knuth volume 2, because there were major changes to that part of the
book between the first edition, the second edition, and the third
edition. I think the second edition is the best if you want to
understand this area, rather than just copy an algorithm out of the
book).

--
--Tim Smith
.



Relevant Pages

  • Re: Math logic
    ... processors mask out all ... a fast algorithm if it works, ... Would be great if I could replace multiple MULs, ... The input value can have up to 8 significant digits, ...
    (comp.lang.asm.x86)
  • Re: Prime Factorization and Digit Congruence
    ... three digits in the first three integral moduli from zero ... > with alternating digits than with alternating groups of three digits. ... Now a hundred minus one, ninety-nine, is a multiple of eleven, ...
    (sci.math)
  • Re: Prime Factorization and Digit Congruence
    ... > subtracting groups of 3 digits when checking for divisibility by x, ... grouped digits for any positive integer x for any positive integer ... first describing how many units there are to make a multiple of seven, ... divisibility tests, for seven in decimal, and is noted to have been ...
    (sci.math)
  • Re: calculate value of 73!
    ... >> digits. ... The Standard imposes no maxima on precision levels - only minima. ... It is, however, true that the writing of "multiple ...
    (comp.lang.c)
  • Re: A Simplified Number System
    ... See D.E. Knuth, the Art of Computer Programming. ... you allow digits after the positional point. ... because obviously when we take the common meaning ...
    (sci.lang)