Too big integers

H

hobbs

Hi all

I want to make a program that will need to use too long integers and
the biggest size that I know is unsigned long, which stores numbers
until 4294967295 (in my Turbo C 3.1), but this size is too small for
what I want to do. So, how can I store numbers bigger than this one in
C?

Thanks, Guilherme
 
A

Alexander Bartolich

begin followup to hobbs:
So, how can I store numbers bigger than this one in C?

Neither language nor standard library offer any direct solution.
Some contemporary compilers offer an additional (non-standard)
64-bit integer type, going by the name of "long long" or __int64.

For custom big-number libraries there are two approaches:

1. Binary coded decimals
2. Array of words

Probably your best option is to grab a free library.
My recommendation is

http://www.swox.com/gmp/

though I can't say whether it will work on your particular platform.
 
J

Jack Klein

begin followup to hobbs:

Neither language nor standard library offer any direct solution.
Some contemporary compilers offer an additional (non-standard)
64-bit integer type, going by the name of "long long" or __int64.

[snip]

__int64 is indeed non-standard, but "long long" has been part of the
ISO C standard since October 1999, and of the ANSI standard since May
2000.

Any compiler that does not supply signed and unsigned long long types
of at least 64 bits does not conform to the current C standard.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
Y

Yoni Rabkin

Not only is writing your own large number math library relatively easy,
it is also a fun and educational process which might teach you about
algorithms and the C language.

Note that if you are going to write your own it will not be as fast as
existing "bignum" libraries such as GMP.
 
J

Jonathan Hoyle

Neither language nor standard library offer any direct solution.
Some contemporary compilers offer an additional (non-standard)
64-bit integer type, going by the name of "long long" or __int64.

"long long" is defined in the ANSI C 1999 standard, so it is fully
supported by the language (although you may have to check to see if
your compile is modernized enough).

Jonathan Hoyle
Gene Codes Corporation
 
M

Manish Singh

Hi all

I want to make a program that will need to use too long integers and
the biggest size that I know is unsigned long, which stores numbers
until 4294967295 (in my Turbo C 3.1), but this size is too small for
what I want to do. So, how can I store numbers bigger than this one in
C?

Thanks, Guilherme

1. If you don't know what bigger integers are for, how can you even design
a program which makes use of them? Hint: Cryptography, PI value etc.

2. For how long you'll be using that old DOS based compiler? Hint: Upgrade.

3. For arbitrary precision arithmetic, either code your own routines (out of
question) or use available libraries such as MIRACL or GMP.

4. My pleasure!

Regards,
Manish Singh
 
B

Brett

1. If you don't know what bigger integers are for, how can you even design
a program which makes use of them? Hint: Cryptography, PI value etc.

2. For how long you'll be using that old DOS based compiler? Hint: Upgrade.

3. For arbitrary precision arithmetic, either code your own routines (out of
question) or use available libraries such as MIRACL or GMP.

Why is "coding your own" out of the question? I just finished doing it
-- took only a few days. I definitely recommend reading up on the
subject, "Numerical Recipes in C" or "Art of Computer Programming -
Seminumerical Algorithms" by Knuth.
 
K

Keith Thompson

"long long" is defined in the ANSI C 1999 standard, so it is fully
supported by the language (although you may have to check to see if
your compile is modernized enough).

Few C compilers fully support the C99 standard yet, but many compilers
provide "long long" as an extension (it was based on existing
practice, after all).

I don't think any of the C compilers I use fail to provide a
"long long" type of at least 64 bits -- but then, as you can tell from
my sig, I probably don't work in a typical environemnt.
 
K

Keith Thompson

Yoni Rabkin said:
Not only is writing your own large number math library relatively easy,
it is also a fun and educational process which might teach you about
algorithms and the C language.

Note that if you are going to write your own it will not be as fast as
existing "bignum" libraries such as GMP.

It may also not be as correct.

If your goal is to wrote reliable software, use an existing "bignum"
library that's already been thoroughly tested. If your goal is to
learn something about C programming and/or to have some fun, by all
means roll your own.
 
H

hobbs

Thanks for the hints, I've already started writing my own library to
use these numbers because my old compiler doesn't offer the 64-bit
integer type....I'll use an array of unsigned longs and I'll write all
the basic math functions to be used with them.
 
M

Manish Singh

(e-mail address removed) (Brett) wrote in message
[snip]
Why is "coding your own" out of the question? I just finished doing it
-- took only a few days. I definitely recommend reading up on the
subject, "Numerical Recipes in C" or "Art of Computer Programming -
Seminumerical Algorithms" by Knuth.

Writing your own is definitely worth the effort. But it's OOQ in case of the OP
because the OP seems to have no idea where the big integers can be implemented.

In other words, coding my own encryption algorithm is out of question if I don't
know where it can be implemented.

Regards,
Manish Singh
 
R

Richard Heathfield

Manish said:
(e-mail address removed) (Brett) wrote in message

[snip]
Why is "coding your own" out of the question? I just finished doing it
-- took only a few days. I definitely recommend reading up on the
subject, "Numerical Recipes in C" or "Art of Computer Programming -
Seminumerical Algorithms" by Knuth.

Writing your own is definitely worth the effort. But it's OOQ in case of
the OP because the OP seems to have no idea where the big integers can be
implemented.

I don't understand what you mean by "where" in this context. Surely memory
is the usual place to implement this stuff?
In other words, coding my own encryption algorithm is out of question if I
don't know where it can be implemented.

In memory, as with any other algorithm?

Could you be clearer about what you mean by "where", please?
 
R

Richard Heathfield

Peter said:
His name doesn't look natively English. Have you taken that into
consideration?

No. I'm trying to help him, not sentence him! :) All that I've taken into
consideration is the fact that I don't understand what he wants. I'd like
to help him, but I can't do that effectively until I understand him. I did
not intend to criticise his English. I merely asked for clarification of
what he meant.
 
R

Richard Heathfield

hobbs said:
Thanks for the hints, I've already started writing my own library to
use these numbers because my old compiler doesn't offer the 64-bit
integer type....I'll use an array of unsigned longs and I'll write all
the basic math functions to be used with them.

You're gonna love division. Hint: keep it as simple as you can, and do lots
of examples on paper.
 
R

Randy Howard

Thanks for the hints, I've already started writing my own library to
use these numbers because my old compiler doesn't offer the 64-bit
integer type....I'll use an array of unsigned longs and I'll write all
the basic math functions to be used with them.

What is wrong with a free, newer compiler? BTW, one that I just started
using recently on Windows platforms is "Dev-C++" which is a nice IDE
front end bundled with gcc.
 
M

Manish Singh

Richard Heathfield said:
No. I'm trying to help him, not sentence him! :) All that I've taken into
consideration is the fact that I don't understand what he wants. I'd like
to help him, but I can't do that effectively until I understand him. I did
not intend to criticise his English. I merely asked for clarification of
what he meant.

I should have used 'how' but somehow managed to write 'where', which fits
perfect in my native language frame.

BTW, what makes you think that I need to get help from someone? I didn't ask
for it. The OP seemed to have problems with bignums and I replied with what I
had in my mind, ATM. All I meant to say is if someone doesn't know how to make
use of a motorcycle, he's not supposed to manufacture or repair them.

I know you're not critici(s/z)ing my English. I don't care if it doesn't live
upto the Internatinal Standards. Oh well, the fact is I fail to see what exactly
you meant to say when you wrote "I don't understand what he wants.".
What *I* want? Gosh!

I don't want nothing. I never expected someone to interrupt me and ask what I
wanted, when in fact I was trying to help the OP. Pathetic!

Regards,
Manish
 
K

Keith Thompson

I know you're not critici(s/z)ing my English. I don't care if it
doesn't live upto the Internatinal Standards. Oh well, the fact is I
fail to see what exactly you meant to say when you wrote "I don't
understand what he wants.". What *I* want? Gosh!

I don't want nothing. I never expected someone to interrupt me and
ask what I wanted, when in fact I was trying to help the
OP. Pathetic!

Nobody interrupted you. Richard was trying to be helpful, just as you
were; that's why we're here. There's absolutely nothing pathetic
about it. It looks like you're taking offense where none was
intended.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top