🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.mathematics
Article #11486

Re: I need a C++ library for arbitrary precision arithmetic

#11486
From: Paul Mackenzie
Date: Sun, 03 Dec 1995 00:00
48 lines
2910 bytes
cs321509@student.uq.edu.au (Nicholas Sheppard) wrote:
 >Does anybody know if and where I can find a C++ library for doing
 >arbitrary (or, at least, very large) precision integer arithmetic?
 >I.e. a #include file that I can compile into my program to allow my
 >program to work on integers using more than the 32 bits for a long
 >int.
 >
 >	Z
 >
 >--
 >Computer Systems Engineering / Mathematics |      Eat right. Exercise.
 >University of Queensland                   |          Die Anyway.
 >cs321509@student.uq.edu.au                 |
 >http://student.uq.edu.au/~cs321509   --->  | World of Cynicism & Negativity

I have'nt seen one, but I guess they exist. Why don't you try and write one
yourself. It is not easy, I have been trying to write one. I assume you are
interested in integral maths. The way to go about it is to input the number as
a string, for each character of the string convert this down to Binary Coded
Decimal, e.g subtract the number 48 from the ASCII char will result in a BCD
string. Then convert the BCD string to pure binary bitstream. You will need to
allocate a further char buffer for the binary stream. E.G. for the string 98
consisting of two ASCII chars convert this down to ASCII chars HT BS, then use
a routine to convert BCD to binary bitstream, which in this example will result
in a 16 bit integer. The binary bitstream consists of a memory buffer of type
char. The main problem is determining how many chars you will need for your
bitstream for a very large number e.g. 98498749814872647627647478614784741764.  

You can then perform binary arithmetic on the bitstreams. You will need a
further function to reconvert this binary bitstream to a string.

So you will need the following functions
Convert string to binary bitstream function
binary addition and multiplication functions
Convert binary bitstream to a string function

The first and last are the hardest ones. A system such as the above
theoretically would be able to handle strings having upto 5.2 x 10^8 chars.
Very large numbers indeed!!! The reason for the restriction is that the
functions include integral loops for processing and errors will occur once you
go above this limit. But your RAM will probably give out before then.  

For your information the RSA data encryption  used by Netscape and others
relies on very large scale integral mathematics.

Best of luck
Regards
Paul Mackenzie
Technical Details
Message-ID: <951203$231637$310macpaul1@oz-email.com.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <48lugm$osc@dingo.cc.uq.oz.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d67e,78d88d7a3d0b4fe1,start
X-Google-Attributes: gid10d67e,public
From: Paul Mackenzie <macpaul1@oz-email.com.au>
Subject: Re: I need a C++ library for arbitrary precision arithmetic
Date: 1995/12/03
Message-ID: <951203$231637$310macpaul1@oz-email.com.au>
X-Deja-AN: 120764583
references: <48lugm$osc@dingo.cc.uq.oz.au>
organization: OzEmail Pty Ltd - Australia
newsgroups: aus.mathematics