Fully Portable Big Number Library

  • Thread starter Tomás Ó hÉilidhe
  • Start date
T

Tomás Ó hÉilidhe

I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.

What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here had good experiences with a particular Big
Number library?
 
P

Phil Carmody

Tomás Ó hÉilidhe said:
I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.

What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here had good experiences with a particular Big
Number library?

GMP is supported on a very large number of platforms, and is very
efficient as it's had a lot of effort spent optimising it. It
achieves its portability via the traditional mechanism of a
fairly thorough platform-differentiating configuration stage,
and plenty of use of the pre-processor. Only small amounts of
the code actually being compiled are identical on all platforms.
I use GMP for all my 'small' bignum work (up to a few thousand
digits).

For something simpler, and designed with the express intention
of being a learning experience in how bignums can be implemented
for both the author and user, there's also a library called
'libtommath' which is I believe public domain. It might not work
in "36-bit la-la land", but seems to be portable across modern
32- and 64-bit architectures. (I think I've also run it on 16-bit
architectures too.) That might be good enough for your needs.

Google is your friend.

Phil
--
Richard Heathfield - please do not waste your time mailing unsolicited
Christian ramblings in response to my signatures.

As with the Christian religion, the worst advertisement for Socialism is its
adherents. -- Eric Arthur Blair (1903-1950), The Road to Wigan Pier (1937)
 
V

vippstar

I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.

What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here had good experiences with a particular Big
Number library?

First of all, asking for advice on libraries here is off-topic.
Your questions (and my answers) are:
What's the best Big Number library for C?

Define best (your subject suggests 'fully portable' = 'best', however
you don't mention it in the body of your article)
Has anyone here had good experiences with a particular Big
Number library?

Yes
 
I

Ian Collins

First of all, asking for advice on libraries here is off-topic.
Your questions (and my answers) are:


Define best (your subject suggests 'fully portable' = 'best', however
you don't mention it in the body of your article)


Yes

Well that was about as helpful as a fart in a wetsuit, wasn't it?
 
D

Don Bruder

Tomas O hEilidhe said:
I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.

What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here had good experiences with a particular Big
Number library?

Have you looked into "MIRACL"? I've long since forgotten what the
letters stand for, and have no idea if it's still available, but it was
a C library I used a few years back when I was tinkering with some
*REALLY* big numbers as part of a crypto project. According to memory,
the only practical limitation on it was available RAM - In theory, you
could use it for doing all the math primitives (as well as input and
formatted output, ala printf(), plus several built-in crypto functions)
with arbitrary-length numbers - 5 decimal digits? No problem. 50 of 'em?
500? 5000? Still no problem, although if you expected to exceed a
certain number of decimal digits (I forget the exact number now) you
needed to twiddle a #define in one of the header files and recompile the
library.

Largest number I ever personally saw come out of it (as an intermediate
result from a calculation in the crypto project) took a little less than
8 full screens worth of decimal digits to output to the 80x24 display of
the old Apple //e I was working on at the time. (Which should also tell
you that it's portable, and not all that big... I compiled it for the
enhanced //e's 65C02 processor under Manx Aztec C, and the program that
linked it ran in the main 64K bank of RAM.)
 
U

user923005

I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.

What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here had good experiences with a particular Big
Number library?

Maybe this can help you:
http://pari.math.u-bordeaux.fr/benchs/timings-mpfr.html

I am fond of MPFR.
 
L

Lew Pitcher

Re: Fully Portable Big Number Library
From:
Don Bruder <[email protected]>  (Chaotic Creations Unlimited)
Date:
October 28, 2008 15:21:47
Groups:
comp.lang.c
Tomas O hEilidhe said:
I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.
[snip]
Have you looked into "MIRACL"? I've long since forgotten what the
letters stand for,

MIRACL stands for "Multiprecision Integer and Rational Arithmetic C/C++
Library".

and have no idea if it's still available,

Apparently, it is. Take a look at http://www.shamus.ie/


[snip]
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
U

user923005

A libraries become faster they become bigger and more difficult to set up..

I generally find it is no more difficult than:
../configure
make

If you are using a PC, then the MINGW toolchain is an easy way to
build GNU style projects.
 
P

Peter Nilsson

Tomás Ó hÉilidhe said:
I need a Big Number library. I've been considering
switching my project to C++ but at the moment I'm
exploring the avenue of keeping it in C.

What's the best Big Number library for C? I need
to be able to represent the number (95 ^ 63), which
is approximately (2 ^ 6.6) ^ 63, which is about 2 ^
416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication
on a 512-Bit number.

Ah well in that case, add another 10 minutes onto the 2
spent implementing multiplication. :)
Has anyone here had good experiences with a particular
Big Number library?

I've had good experiences with the simplest of primary
school algorithms.[1] In recent times, I only resort to
genuine bignum algorithms or libraries when the
calculation looks like taking days, not minutes.

Couple your code if you have to, but first determine
that you actually have to.

[1] Try calculating the 73 digit base 16 narcissistic
numbers, with or without a bignumb library.
 
C

CBFalconer

Richard said:
Well said. In almost all other language groups, the focus is on
programming in that language. Naturally the details of the
language standard(s) (if any) are part of the discussion, but
they are not the entirety.

Well, the topic is portable C programming, as defined by the
standard. To me, this means libraries are topical, provided that
the library source is available, and primarily in standard C.
Queries about library availability seems quite topical too.

Observation: Big Number libraries do not require non-standard C.
 
U

user923005

Tomás Ó hÉilidhe said:
I need a Big Number library. I've been considering
switching my project to C++ but at the moment I'm
exploring the avenue of keeping it in C.
What's the best Big Number library for C? I need
to be able to represent the number (95 ^ 63), which
is approximately (2 ^ 6.6) ^ 63, which is about 2 ^
416, so we're talking about maybe a 512-Bit number.

So I need to be able to do division and multiplication
on a 512-Bit number.

Ah well in that case, add another 10 minutes onto the 2
spent implementing multiplication. :)
Has anyone here had good experiences with a particular
Big Number library?

I've had good experiences with the simplest of primary
school algorithms.[1] In recent times, I only resort to
genuine bignum algorithms or libraries when the
calculation looks like taking days, not minutes.

Couple your code if you have to, but first determine
that you actually have to.

[1] Try calculating the 73 digit base 16 narcissistic
numbers, with or without a bignumb library.

http://homepages.cwi.nl/~dik/english/mathematics/armstrong.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top