Large number in C

Discussion in 'C Programming' started by KC, Apr 17, 2004.

  1. KC

    KC Guest

    How can I represent a 22-digit integer in C? float is not large enough.

    Thanks!
     
    KC, Apr 17, 2004
    #1
    1. Advertising

  2. begin followup to KC:
    > How can I represent a 22-digit integer in C?


    Is that 22 digits in decimal radix?

    $ echo 'scale=3; l(10)/l(2)*22' | bc -ql
    73.062

    Requires significantly more than 64 bits so 'long long' does not help.

    > float is not large enough.


    float is typically 32 bits for both mantissa and exponent giving
    about 7 decimal digits. double extends that to about 15.
    The built-in data types of C are not enough for your problem.

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

    --
    Für Google, Tux und GPL!
     
    Alexander Bartolich, Apr 17, 2004
    #2
    1. Advertising

  3. On 17 Apr 2004 06:44:31 -0700, (KC) wrote:

    >How can I represent a 22-digit integer in C? float is not large enough.
    >


    Standard C does not have a type guaranteed to satisfy you on all
    conforming implementations.

    It is possible that you could find an implementation that runs on
    your system with 128 bit long long that would work.

    More likely, you can use one of the numerous "bignum"
    implementations which use only standard features and are therefore
    extremely portable. I have played with CLINT from Richard Heathfield
    at www.rjgh.co.uk. It is free and I think it will do what you want.


    <<Remove the del for email>>
     
    Barry Schwarz, Apr 17, 2004
    #3
  4. KC wrote:
    > How can I represent a 22-digit integer in C? float is not large enough.


    Since the range of 22-digit integers in approximately pow(2,69.8) to
    pow(2,73.1), find an implementation that has a type with 70+ bits to
    represent *some* 22-digit integers, or 74+ bits to represent *all* the
    22-digit integers.

    You could join together two or more shorter integer types in a struct,
    or, if you don't want to do that, find a free open-source bignum library
    on the web. There are some googlehints in that last clause.
     
    Martin Ambuhl, Apr 17, 2004
    #4
  5. KC

    Rakesh Kumar Guest

    You can -

    Try a linked list implementation, with possibly a long integer as a
    member, if you want to learn. It would be fun.
    - Or -
    Use any of the suggested libraries in the prev. replies if you want the
    job done right away.

    All the best.

    KC wrote:
    > How can I represent a 22-digit integer in C? float is not large enough.
    >
    > Thanks!


    --

    --
    Rakesh Kumar
    ** Remove nospamplz from my email address for my real email **
     
    Rakesh Kumar, Apr 20, 2004
    #5
    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. nospam
    Replies:
    4
    Views:
    494
    Thomas Reinemann
    Jun 6, 2005
  2. Lionel

    Large number of files...

    Lionel, Feb 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    385
    Kevin Spencer
    Feb 21, 2005
  3. Bogdan Nedelcu

    Large number of compiled dll's

    Bogdan Nedelcu, Mar 5, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    376
    Bogdan Nedelcu
    Mar 6, 2005
  4. Ketchup
    Replies:
    1
    Views:
    259
    Jan Tielens
    May 25, 2004
  5. Replies:
    5
    Views:
    919
    Xho Jingleheimerschmidt
    Apr 2, 2009
Loading...

Share This Page