big number crunching in C

S

Shuo Xiang

Greetings:

Does any one know how high-precision integer +-*/ are implemented in C
using char[]? I'm talking about integers that have say, 2000 digits.

I found a few "bignum.c" on the net but all of them are too long to
implement in the session of a single computing contest (3 hours), so
I'm looking for shorter ones.

Regards,

Shuo Xiang
 
M

Mike Wahler

Shuo Xiang said:
Greetings:

Does any one know how high-precision integer +-*/ are implemented in C

Numeric precision is not specified in terms of
operators, but of the numeric types' representations.
See the macros in <limits.h> for the allowed range for each
integral type, and in <float.h> for the same info about
each floating point type. e.g. 'INT_MAX' is the highest
value allowed for type 'int', 'DBL_MAX' the highest for
type 'double', etc.
using char[]?

Arithmetic operators cannot be applied to arrays.
If you mean you want to store your values as 'one
digit per character', then the size is only limited
by available storage. But you'll have to code the
operators yourself. Not a small task. Better might
be to find an already existing library. www.google.com

I'm talking about integers that have say, 2000 digits.

You'll need to write or obtain a library for that.

I found a few "bignum.c" on the net but all of them are too long to
implement

They're already implemented. Your program can *use* them.
in the session of a single computing contest (3 hours), so
I'm looking for shorter ones.

I'm looking for automobile that can be driven from Los Angeles
to New York in six hours.

"I want a new drug"
-- Huey Lewis

-Mike
 
T

Tom Zych

Shuo said:
Does any one know how high-precision integer +-*/ are implemented in C
using char[]? I'm talking about integers that have say, 2000 digits.

They aren't. Standard C doesn't have high precision integers. There
are various libraries that do, but I doubt any of them use arrays of
char.
I found a few "bignum.c" on the net but all of them are too long to
implement in the session of a single computing contest (3 hours), so
I'm looking for shorter ones.

If you mean you need to be able to hack up some bignum code in a few
hours for a contest, offhand I'd advise putting the least
significant digit in [0], store them as 0-9 instead of '0'-'9', and
think about how you do +-*/ with paper and pencil.
 
G

Glen Herrmannsfeldt

Shuo Xiang said:
Greetings:

Does any one know how high-precision integer +-*/ are implemented in C
using char[]? I'm talking about integers that have say, 2000 digits.

I found a few "bignum.c" on the net but all of them are too long to
implement in the session of a single computing contest (3 hours), so
I'm looking for shorter ones.

All except bugnum divided by bignum can be done in a 3 hour contest.

Things like computing pi or e to many digits don't need bignum divided by
bignum.

-- glen
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top