473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Fully Portable Big Number Library


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?
Oct 27 '08 #1
14 9018
Tomás Ó hÉilidhe <to*@lavabit.comwrites:
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)
Oct 27 '08 #2
On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
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
Oct 28 '08 #3
vi******@gmail.com said:
On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
>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.
Why? It seems to me that the topic of this group is C programming,
regardless of platform. Library usage is certainly a part of programming.
Okay, I can understand - and agree - that detailed discussions on the
usage of platform-specific libraries is off-topic here, but what he's
asking for is a fully portable library.

I know of one reason why people might demur from helping the OP, but
topicality isn't it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 28 '08 #4
vi******@gmail.com wrote:
On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
>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
Well that was about as helpful as a fart in a wetsuit, wasn't it?

--
Ian Collins
Oct 28 '08 #5
On Tue, 28 Oct 2008 09:03:09 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>vi******@gmail.com said:
>On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
>>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.

Why? It seems to me that the topic of this group is C programming,
regardless of platform. Library usage is certainly a part of programming.
Okay, I can understand - and agree - that detailed discussions on the
usage of platform-specific libraries is off-topic here, but what he's
asking for is a fully portable library.

I know of one reason why people might demur from helping the OP, but
topicality isn't it.
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.


Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
Oct 28 '08 #6
In article
<d9**********************************@w1g2000prk.g ooglegroups.com>,
Tomas O hEilidhe <to*@lavabit.comwrote:
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.)

--
Don Bruder - da****@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info
Oct 28 '08 #7
On Oct 27, 4:41*am, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
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.
Oct 28 '08 #8
On October 28, 2008 15:21, in comp.lang.c, Don Bruder (da****@sonic.net)
wrote:
Re: Fully Portable Big Number Library
From:
Don Bruder <da****@sonic.net>Â*Â*(Chaotic Creations Unlimited)
Date:
October 28, 2008 15:21:47
Groups:
comp.lang.c
In article
<d9**********************************@w1g2000prk.g ooglegroups.com>,
Tomas O hEilidhe <to*@lavabit.comwrote:
>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. ------
Oct 28 '08 #9
"Tomás Ó hÉilidhe" <to*@lavabit.comwrote in message
>
What's the best Big Number library for C?
A libraries become faster they become bigger and more difficult to set up.
If speed is your priority you could do worse than use a GNU job that uses
things like Fast Fourier transforms for multiplications.

If you simply want a not grossly-inefficient library to drop into code, pull
over the Basic Algorithms bignum source file, from my website.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Oct 28 '08 #10
On Oct 28, 2:01*pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
"Tomás Ó hÉilidhe" <t...@lavabit.comwrote in message
What's the best Big Number library for C?

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.
If speed is your priority you could do worse than use a GNU job that uses
things like Fast Fourier transforms for multiplications.

If you simply want a not grossly-inefficient library to drop into code, pull
over the Basic Algorithms bignum source file, from my website.
Oct 28 '08 #11
Tomás Ó hÉilidhe <t...@lavabit.comwrote:
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.
<http://groups.google.com/group/comp.lang.c/msg/696064e8b22a223d>
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.

--
Peter
Oct 28 '08 #12
Ian Collins wrote:
vi******@gmail.com wrote:
>Tomás Ó hÉilidhe <t...@lavabit.comwrote:
.... snip ...
>>
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

Well that was about as helpful as a fart in a wetsuit, wasn't it?
Which may be a great relief to the farter. :-) Define terms.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 29 '08 #13
Richard Harter wrote:
Richard Heathfield <rj*@see.sig.invalidwrote:
>vi******@gmail.com said:
.... snip ...
>>
>>First of all, asking for advice on libraries here is off-topic.

Why? It seems to me that the topic of this group is C programming,
regardless of platform. Library usage is certainly a part of
programming. Okay, I can understand - and agree - that detailed
discussions on the usage of platform-specific libraries is off-
topic here, but what he's asking for is a fully portable library.

I know of one reason why people might demur from helping the OP,
but topicality isn't it.

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.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 29 '08 #14
On Oct 28, 2:51*pm, Peter Nilsson <ai...@acay.com.auwrote:
Tomás Ó hÉilidhe <t...@lavabit.comwrote:
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.

<http://groups.google.com/group/comp.lang.c/msg/696064e8b22a223d>
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...armstrong.html
Oct 29 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Danilo Kempf | last post by:
Folks, maybe one of you could be of help with this question: I've got a relatively portable application which I'm extending with a plugin interface. While portability (from a C perspective) is...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
13
by: Tomás | last post by:
Let's start off with: class Nation { public: virtual const char* GetName() const = 0; } class Norway : public Nation { public: virtual const char* GetName() const
4
by: Frederick Gotham | last post by:
I was pondering over writing a fully-portable version of <limits.h(e.g. such things as: #define UINT_MAX ((unsigned)-1) , when something occurred to me. Just recently on this newsgroup, I and...
9
by: Martin Wells | last post by:
I'm doing an embedded systems project and I'm programming it as fully- portable C89 (except of course for setting the pin values). I need to put delays in the program, in the vicinity of 250 ms....
18
by: Tomás Ó hÉilidhe | last post by:
(SHA-1 is a cryptographic hash function. For info on what SHA-1 is: http://en.wikipedia.org/wiki/SHA-1) I'm writing fullportable C89 code that needs to make use of the SHA-1 algorithm. Does...
69
by: Bill Reid | last post by:
This is how I handle a check that the last character of a text file is a newline: /* checks if newline is last character of text file */ unsigned check_text_file_newline_termination(FILE...
23
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.