Too big integers

Discussion in 'C Programming' started by hobbs, Dec 25, 2003.

  1. hobbs

    hobbs Guest

    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
     
    hobbs, Dec 25, 2003
    #1
    1. Advertisements

  2. hobbs

    Eric Guest

    google for a 'bignum' library or develop your own.
     
    Eric, Dec 26, 2003
    #2
    1. Advertisements

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

    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.
     
    Alexander Bartolich, Dec 26, 2003
    #3
  4. hobbs

    Jack Klein Guest

    [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
     
    Jack Klein, Dec 26, 2003
    #4
  5. hobbs

    Yoni Rabkin Guest

    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.
     
    Yoni Rabkin, Dec 26, 2003
    #5
  6. Neither language nor standard library offer any direct solution.
    "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
     
    Jonathan Hoyle, Dec 26, 2003
    #6
  7. hobbs

    Manish Singh Guest

    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
     
    Manish Singh, Dec 26, 2003
    #7
  8. hobbs

    Brett Guest

    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.
     
    Brett, Dec 26, 2003
    #8
  9. 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.
     
    Keith Thompson, Dec 26, 2003
    #9
  10. 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.
     
    Keith Thompson, Dec 26, 2003
    #10
  11. hobbs

    hobbs Guest

    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.
     
    hobbs, Dec 27, 2003
    #11
  12. hobbs

    Manish Singh Guest

    (Brett) wrote in message
    [snip]
    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
     
    Manish Singh, Dec 27, 2003
    #12
  13. I don't understand what you mean by "where" in this context. Surely memory
    is the usual place to implement this stuff?
    In memory, as with any other algorithm?

    Could you be clearer about what you mean by "where", please?
     
    Richard Heathfield, Dec 27, 2003
    #13
  14. ^^^^^^^^^^^^
    ....
    His name doesn't look natively English. Have you taken that into
    consideration?
     
    Peter Pichler, Dec 27, 2003
    #14
  15. 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.
     
    Richard Heathfield, Dec 28, 2003
    #15
  16. You're gonna love division. Hint: keep it as simple as you can, and do lots
    of examples on paper.
     
    Richard Heathfield, Dec 28, 2003
    #16
  17. hobbs

    Randy Howard Guest

    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.
     
    Randy Howard, Dec 28, 2003
    #17
  18. hobbs

    Paul Hsieh Guest

    It looks like you can get a start here:

    http://camino.rutgers.edu/ut/utsa/cs3343/lecture20.html
     
    Paul Hsieh, Dec 28, 2003
    #18
  19. hobbs

    Manish Singh Guest

    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
     
    Manish Singh, Dec 28, 2003
    #19
  20. 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.
     
    Keith Thompson, Dec 29, 2003
    #20
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.