big number crunching in C

Discussion in 'C Programming' started by Shuo Xiang, Sep 25, 2003.

  1. Shuo Xiang

    Shuo Xiang Guest

    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
    Shuo Xiang, Sep 25, 2003
    #1
    1. Advertising

  2. Shuo Xiang

    Mike Wahler Guest

    "Shuo Xiang" <> wrote in message
    news:...
    > 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
    Mike Wahler, Sep 25, 2003
    #2
    1. Advertising

  3. Shuo Xiang

    Tom Zych Guest

    Shuo Xiang wrote:

    > 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.

    --
    Tom Zych
    This is a fake email address to thwart spammers.
    Real address: echo '' | rot13
    Tom Zych, Sep 26, 2003
    #3
  4. "Shuo Xiang" <> wrote in message
    news:...
    > 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
    Glen Herrmannsfeldt, Sep 26, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Ankerl

    EJB + number crunching

    Martin Ankerl, Aug 18, 2005, in forum: Java
    Replies:
    8
    Views:
    400
    Roedy Green
    Aug 23, 2005
  2. Ted
    Replies:
    5
    Views:
    687
  3. Replies:
    21
    Views:
    1,678
    northerntechie
    Mar 26, 2008
  4. Replies:
    40
    Views:
    1,251
    Roedy Green
    Jun 23, 2008
  5. Kevin McMurtrie
    Replies:
    35
    Views:
    1,090
    Arne Vajhøj
    Aug 23, 2009
Loading...

Share This Page