Large numbers in Pascal
Author Message
Large numbers in Pascal

Hi !

I have a question:
How can i use very large numbers (2000 bit) in Pascal ?

Tnx !
-------------------------------------------------------
Christian Becker

-------------------------------------------------------

Mon, 29 Nov 1999 03:00:00 GMT
Large numbers in Pascal

Thu, 12 Jun 1997 16:15:42 in comp.lang.pascal.misc, Christian Becker

Quote:

>Hi !

>I have a question:
>How can i use very large numbers (2000 bit) in Pascal ?

>Tnx !
>-------------------------------------------------------
>Christian Becker

>-------------------------------------------------------

Duff SigSep - see sig.

My   http://www.merlyn.demon.co.uk/programs/longmult.pas    may give you
a clue; it handles numbers of many digits, stored in strings.  It's very
old, and I would not hold it out as an example of "style".

However, you should prefer to use "array of byte" to store your numbers,
and build up from byte arithmetic.  Or possibly "array of word".

You will need to build almost all operations up from simpler ones.

As this is the Misc newsgroup, we cannot give any guidance specific to
whatever version of Pascal you have.
--

Web URL: http://www.merlyn.demon.co.uk/ -- includes FAQqish topics and links.
Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

Mon, 29 Nov 1999 03:00:00 GMT
Large numbers in Pascal

Quote:

> I have a question:
> How can i use very large numbers (2000 bit) in Pascal ?

I'm sure solutions are already in SWAG, but it isn't difficult to
implement an "infinite" precision integer package in Pascal.  One (not
very optimal) way to do this is to express a number as a series of
digits in a linked list (i.e. "123" is the list "1" -> "2" -> "3").  You
need to develop functions or procedures to do arithmetic on these
"numbers", using the rules you learned in elementary school (add the
ones, take the carry, add the tens and the carry, take the carry, add
the hundreds and the carry, etc.).  You are only limited by computer
memory.

Note that the above is decidedly NOT an efficient implementation.
However, you can easily generalize this idea of a representation as a
list, and do it all in Pascal, without needing assembler.

Bob Schor
Pascal Enthusiast

Mon, 29 Nov 1999 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages