Big Int support

  • Not exactly a Cocoa-related question, but it could be incorporated into
    a Cocoa program.  Is there a library or way to create 'big int' support
    so a number isn't limited to the particular bounds of int, float, or
    even an unsigned long?

    Occasionally I need to do large number calculations (such as 2^1000
    which is equal to
    107150860718626732094842504906000181056140481170553360744375038837035105
    112493612249319837881569585812759467291755314682518714528569231404359845
    775746985748039345677748242309854210746050623711418779541821530464749835
    819412673987675591655439460770629145711964776865421676604298316526243868
    37205668069376 according to Mathematica), and it would be nice if I
    could figure out how to do this myself so I wouldn't have to rely on
    Mathematica (which is not cheap software if you aren't in Academia).

    Chad Armstrong
    <edenwaith...>
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Monday, Jun 2, 2003, at 13:28 US/Eastern, Chad Armstrong wrote:

    > Not exactly a Cocoa-related question, but it could be incorporated
    > into a Cocoa program.  Is there a library or way to create 'big int'
    > support so a number isn't limited to the particular bounds of int,
    > float, or even an unsigned long?

    Check out NSDecimalNumber.

    --
    http://homepage.mac.com/clarkcox3/
    <clarkcox3...>
    Clark S. Cox, III
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • I may have misunderstood your question, but here's a stab at it anyway.
    If you're just talking about doing simple calculations on big numbers,
    you can use the UNIX command "bc". It's a handle little
    sort-of-desktop-calculator, and it's got a "man" page. For instance,
    you can use "bc" to calculate 2-to-the-one-thousandth. (Or 2^10000, or
    10^10000, or any similar large number.)

    [monty:~] jeff% bc
    bc 1.05
    Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation,
    Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'.
    2^1000
    10715086071862673209484250490600018105614048117055336074437503883703\
    51051124936122493198378815695858127594672917553146825187145285692314\
    04359845775746985748039345677748242309854210746050623711418779541821\
    53046474983581941267398767559165543946077062914571196477686542167660\
    429831652624386837205668069376

    (To get out of "bc", type control-D.)

    On Monday, June 2, 2003, at 12:28  PM, Chad Armstrong wrote:

    > Not exactly a Cocoa-related question, but it could be incorporated
    > into a Cocoa program.  Is there a library or way to create 'big int'
    > support so a number isn't limited to the particular bounds of int,
    > float, or even an unsigned long?

    --
    <jharrell...>
    http://homepage.mac.com/jharrell
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • From: Wayne Hasley <whasley...>
    Date: Mon Jun 2, 2003  3:40:57  PM US/Eastern
    To: Chad Armstrong <edenwaith...>
    Subject: Re: Big Int support

    On Monday, June 2, 2003, at 01:28  PM, Chad Armstrong wrote:

    > Not exactly a Cocoa-related question, but it could be incorporated
    > into a Cocoa program.  Is there a library or way to create 'big int'
    > support so a number isn't limited to the particular bounds of int,
    > float, or even an unsigned long?

    Finally a question I can answer!

    You want an arbitrary-precision math library.

    A long time ago I ported similar code to the Macintosh

    These are usually done using BCD (Binary Coded Decimal).

    I did a Google search. IBM provides source for their decNumber package;
    an arbitrary-precision implementation of the specifications in ANSI C.

    Warning! There are some heavy license requirements in this package. You
    might want to search for another.

    See http://www.alphaworks.ibm.com/tech/decNumber

    Wayne
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • would this really work, though?  Here's from the documentation on
    NSDecimalNumber:

    > NSDecimalNumber, an immutable subclass of NSNumber, provides an
    > object-oriented wrapper for doing base-10 arithmetic. An instance can
    > represent any number that can be expressed as mantissa x 10^exponent
    > where mantissa is a decimal integer up to 38 digits long, and exponent
    > is an integer from -128 through 127.

    hence, there wouldn't really be enough precision to detail all of
    Chad's number:

    > (such as 2^1000 which is equal to
    > 10715086071862673209484250490600018105614048117055336074437503883703510
    > 51124936122493198378815695858127594672917553146825187145285692314043598
    > 45775746985748039345677748242309854210746050623711418779541821530464749
    > 83581941267398767559165543946077062914571196477686542167660429831652624
    > 386837205668069376 according to Mathematica)

    is there a class that could store and do arithmetic on an effectively
    infinite number?  certainly not infinite truly, but enough so that
    precision is not lost when working with numbers like 2^10^100.

    ~ john

    On Monday, June 2, 2003, at 12:39  PM, Clark S. Cox III wrote:

    > On Monday, Jun 2, 2003, at 13:28 US/Eastern, Chad Armstrong wrote:
    >
    >> Not exactly a Cocoa-related question, but it could be incorporated
    >> into a Cocoa program.  Is there a library or way to create 'big int'
    >> support so a number isn't limited to the particular bounds of int,
    >> float, or even an unsigned long?
    >
    > Check out NSDecimalNumber.

    =================
    support the arts!
    www.smadness.com

    updated Jan 21 2003
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • openssl (headers come with Jaguar) has a Big Number structure.

    http://www.openssl.org/docs/crypto/bn.html

    I've used it, for crypto stuff, but it could be useful on it's own.

    -aaron

    At 4:48 PM -0500 6/2/03, john gale wrote:
    > would this really work, though?  Here's from the documentation on
    > NSDecimalNumber:
    >
    >> NSDecimalNumber, an immutable subclass of NSNumber, provides an
    >> object-oriented wrapper for doing base-10 arithmetic. An instance
    >> can represent any number that can be expressed as mantissa x
    >> 10^exponent where mantissa is a decimal integer up to 38 digits
    >> long, and exponent is an integer from -128 through 127.
    >
    > hence, there wouldn't really be enough precision to detail all of
    > Chad's number:
    >
    >> (such as 2^1000 which is equal to
    >> 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
    >> according to Mathematica)
    >
    > is there a class that could store and do arithmetic on an
    > effectively infinite number?  certainly not infinite truly, but
    > enough so that precision is not lost when working with numbers like
    > 2^10^100.
    >
    >
    > ~ john
    >
    >
    > On Monday, June 2, 2003, at 12:39  PM, Clark S. Cox III wrote:
    >
    >> On Monday, Jun 2, 2003, at 13:28 US/Eastern, Chad Armstrong wrote:
    >>
    >>> Not exactly a Cocoa-related question, but it could be incorporated
    >>> into a Cocoa program.  Is there a library or way to create 'big
    >>> int' support so a number isn't limited to the particular bounds of
    >>> int, float, or even an unsigned long?
    >>
    >> Check out NSDecimalNumber.
    >
    > =================
    > support the arts!
    > www.smadness.com
    >
    > updated Jan 21 2003
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month june 2003 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Go to today