Fully Portable Big Number Library

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

    #1

    Fully Portable Big Number Library


    I need a Big Number library. I've been considering switching my
    project to C++ but at the moment I'm exploring the avenue of keeping
    it in C.

    What's the best Big Number library for C? I need to be able to
    represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
    which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.

    So I need to be able to do division and multiplication on a 512-Bit
    number. Has anyone here had good experiences with a particular Big
    Number library?
  • Phil Carmody

    #2
    Re: Fully Portable Big Number Library

    Tomás Ó hÉilidhe <toe@lavabit.co mwrites:
    I need a Big Number library. I've been considering switching my
    project to C++ but at the moment I'm exploring the avenue of keeping
    it in C.
    >
    What's the best Big Number library for C? I need to be able to
    represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
    which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
    >
    So I need to be able to do division and multiplication on a 512-Bit
    number. Has anyone here had good experiences with a particular Big
    Number library?
    GMP is supported on a very large number of platforms, and is very
    efficient as it's had a lot of effort spent optimising it. It
    achieves its portability via the traditional mechanism of a
    fairly thorough platform-differentiating configuration stage,
    and plenty of use of the pre-processor. Only small amounts of
    the code actually being compiled are identical on all platforms.
    I use GMP for all my 'small' bignum work (up to a few thousand
    digits).

    For something simpler, and designed with the express intention
    of being a learning experience in how bignums can be implemented
    for both the author and user, there's also a library called
    'libtommath' which is I believe public domain. It might not work
    in "36-bit la-la land", but seems to be portable across modern
    32- and 64-bit architectures. (I think I've also run it on 16-bit
    architectures too.) That might be good enough for your needs.

    Google is your friend.

    Phil
    --
    Richard Heathfield - please do not waste your time mailing unsolicited
    Christian ramblings in response to my signatures.

    As with the Christian religion, the worst advertisement for Socialism is its
    adherents. -- Eric Arthur Blair (1903-1950), The Road to Wigan Pier (1937)

    Comment

    • vippstar@gmail.com

      #3
      Re: Fully Portable Big Number Library

      On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
      I need a Big Number library. I've been considering switching my
      project to C++ but at the moment I'm exploring the avenue of keeping
      it in C.
      >
      What's the best Big Number library for C? I need to be able to
      represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
      which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
      >
      So I need to be able to do division and multiplication on a 512-Bit
      number. Has anyone here had good experiences with a particular Big
      Number library?
      First of all, asking for advice on libraries here is off-topic.
      Your questions (and my answers) are:
      What's the best Big Number library for C?
      Define best (your subject suggests 'fully portable' = 'best', however
      you don't mention it in the body of your article)
      Has anyone here had good experiences with a particular Big
      Number library?
      Yes

      Comment

      • Richard Heathfield

        #4
        Re: Fully Portable Big Number Library

        vippstar@gmail. com said:
        On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
        >I need a Big Number library. I've been considering switching my
        >project to C++ but at the moment I'm exploring the avenue of keeping
        >it in C.
        >>
        >What's the best Big Number library for C? I need to be able to
        >represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
        >which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
        >>
        >So I need to be able to do division and multiplication on a 512-Bit
        >number. Has anyone here had good experiences with a particular Big
        >Number library?
        >
        First of all, asking for advice on libraries here is off-topic.
        Why? It seems to me that the topic of this group is C programming,
        regardless of platform. Library usage is certainly a part of programming.
        Okay, I can understand - and agree - that detailed discussions on the
        usage of platform-specific libraries is off-topic here, but what he's
        asking for is a fully portable library.

        I know of one reason why people might demur from helping the OP, but
        topicality isn't it.

        --
        Richard Heathfield <http://www.cpax.org.uk >
        Email: -http://www. +rjh@
        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
        "Usenet is a strange place" - dmr 29 July 1999

        Comment

        • Ian Collins

          #5
          Re: Fully Portable Big Number Library

          vippstar@gmail. com wrote:
          On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
          >I need a Big Number library. I've been considering switching my
          >project to C++ but at the moment I'm exploring the avenue of keeping
          >it in C.
          >>
          >What's the best Big Number library for C? I need to be able to
          >represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
          >which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
          >>
          >So I need to be able to do division and multiplication on a 512-Bit
          >number. Has anyone here had good experiences with a particular Big
          >Number library?
          >
          First of all, asking for advice on libraries here is off-topic.
          Your questions (and my answers) are:
          >
          >What's the best Big Number library for C?
          >
          Define best (your subject suggests 'fully portable' = 'best', however
          you don't mention it in the body of your article)
          >
          >Has anyone here had good experiences with a particular Big
          >Number library?
          >
          Yes
          Well that was about as helpful as a fart in a wetsuit, wasn't it?

          --
          Ian Collins

          Comment

          • Richard Harter

            #6
            Re: Fully Portable Big Number Library

            On Tue, 28 Oct 2008 09:03:09 +0000, Richard Heathfield
            <rjh@see.sig.in validwrote:
            >vippstar@gmail .com said:
            >
            >On Oct 27, 1:41 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
            >>I need a Big Number library. I've been considering switching my
            >>project to C++ but at the moment I'm exploring the avenue of keeping
            >>it in C.
            >>>
            >>What's the best Big Number library for C? I need to be able to
            >>represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
            >>which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
            >>>
            >>So I need to be able to do division and multiplication on a 512-Bit
            >>number. Has anyone here had good experiences with a particular Big
            >>Number library?
            >>
            >First of all, asking for advice on libraries here is off-topic.
            >
            >Why? It seems to me that the topic of this group is C programming,
            >regardless of platform. Library usage is certainly a part of programming.
            >Okay, I can understand - and agree - that detailed discussions on the
            >usage of platform-specific libraries is off-topic here, but what he's
            >asking for is a fully portable library.
            >
            >I know of one reason why people might demur from helping the OP, but
            >topicality isn't it.
            Well said. In almost all other language groups, the focus is on
            programming in that language. Naturally the details of the
            language standard(s) (if any) are part of the discussion, but
            they are not the entirety.






            Richard Harter, cri@tiac.net
            http://home.tiac.net/~cri, http://www.varinoma.com
            Save the Earth now!!
            It's the only planet with chocolate.

            Comment

            • Don Bruder

              #7
              Re: Fully Portable Big Number Library

              In article
              <d93c8295-e65f-4480-adcd-e2f6f77d9587@w1 g2000prk.google groups.com>,
              Tomas O hEilidhe <toe@lavabit.co mwrote:
              I need a Big Number library. I've been considering switching my
              project to C++ but at the moment I'm exploring the avenue of keeping
              it in C.
              >
              What's the best Big Number library for C? I need to be able to
              represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
              which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
              >
              So I need to be able to do division and multiplication on a 512-Bit
              number. Has anyone here had good experiences with a particular Big
              Number library?
              Have you looked into "MIRACL"? I've long since forgotten what the
              letters stand for, and have no idea if it's still available, but it was
              a C library I used a few years back when I was tinkering with some
              *REALLY* big numbers as part of a crypto project. According to memory,
              the only practical limitation on it was available RAM - In theory, you
              could use it for doing all the math primitives (as well as input and
              formatted output, ala printf(), plus several built-in crypto functions)
              with arbitrary-length numbers - 5 decimal digits? No problem. 50 of 'em?
              500? 5000? Still no problem, although if you expected to exceed a
              certain number of decimal digits (I forget the exact number now) you
              needed to twiddle a #define in one of the header files and recompile the
              library.

              Largest number I ever personally saw come out of it (as an intermediate
              result from a calculation in the crypto project) took a little less than
              8 full screens worth of decimal digits to output to the 80x24 display of
              the old Apple //e I was working on at the time. (Which should also tell
              you that it's portable, and not all that big... I compiled it for the
              enhanced //e's 65C02 processor under Manx Aztec C, and the program that
              linked it ran in the main 64K bank of RAM.)

              --
              Don Bruder - dakidd@sonic.ne t - If your "From:" address isn't on my whitelist,
              or the subject of the message doesn't contain the exact text "PopperAndShado w"
              somewhere, any message sent to this address will go in the garbage without my
              ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info

              Comment

              • user923005

                #8
                Re: Fully Portable Big Number Library

                On Oct 27, 4:41 am, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
                I need a Big Number library. I've been considering switching my
                project to C++ but at the moment I'm exploring the avenue of keeping
                it in C.
                >
                What's the best Big Number library for C? I need to be able to
                represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
                which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
                >
                So I need to be able to do division and multiplication on a 512-Bit
                number. Has anyone here had good experiences with a particular Big
                Number library?
                Maybe this can help you:


                I am fond of MPFR.

                Comment

                • Lew Pitcher

                  #9
                  Re: Fully Portable Big Number Library

                  On October 28, 2008 15:21, in comp.lang.c, Don Bruder (dakidd@sonic.n et)
                  wrote:
                  Re: Fully Portable Big Number Library
                  From:
                  Don Bruder <dakidd@sonic.n et>  (Chaotic Creations Unlimited)
                  Date:
                  October 28, 2008 15:21:47
                  Groups:
                  comp.lang.c
                  In article
                  <d93c8295-e65f-4480-adcd-e2f6f77d9587@w1 g2000prk.google groups.com>,
                  Tomas O hEilidhe <toe@lavabit.co mwrote:
                  >
                  >I need a Big Number library. I've been considering switching my
                  >project to C++ but at the moment I'm exploring the avenue of keeping
                  >it in C.
                  [snip]
                  Have you looked into "MIRACL"? I've long since forgotten what the
                  letters stand for,
                  MIRACL stands for "Multipreci sion Integer and Rational Arithmetic C/C++
                  Library".

                  and have no idea if it's still available,
                  Apparently, it is. Take a look at http://www.shamus.ie/


                  [snip]
                  --
                  Lew Pitcher

                  Master Codewright & JOAT-in-training | Registered Linux User #112576
                  http://pitcher.digitalfreehold.ca/ | GPG public key available by request
                  ---------- Slackware - Because I know what I'm doing. ------


                  Comment

                  • Malcolm McLean

                    #10
                    Re: Fully Portable Big Number Library

                    "Tomás Ó hÉilidhe" <toe@lavabit.co mwrote in message
                    >
                    What's the best Big Number library for C?
                    >
                    A libraries become faster they become bigger and more difficult to set up.
                    If speed is your priority you could do worse than use a GNU job that uses
                    things like Fast Fourier transforms for multiplications .

                    If you simply want a not grossly-inefficient library to drop into code, pull
                    over the Basic Algorithms bignum source file, from my website.

                    --
                    Free games and programming goodies.


                    Comment

                    • user923005

                      #11
                      Re: Fully Portable Big Number Library

                      On Oct 28, 2:01 pm, "Malcolm McLean" <regniz...@btin ternet.comwrote :
                      "Tomás Ó hÉilidhe" <t...@lavabit.c omwrote in message
                      >
                      What's the best Big Number library for C?
                      >
                      A libraries become faster they become bigger and more difficult to set up..
                      I generally find it is no more difficult than:
                      ../configure
                      make

                      If you are using a PC, then the MINGW toolchain is an easy way to
                      build GNU style projects.
                      If speed is your priority you could do worse than use a GNU job that uses
                      things like Fast Fourier transforms for multiplications .
                      >
                      If you simply want a not grossly-inefficient library to drop into code, pull
                      over the Basic Algorithms bignum source file, from my website.

                      Comment

                      • Peter Nilsson

                        #12
                        Re: Fully Portable Big Number Library

                        Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
                        I need a Big Number library. I've been considering
                        switching my project to C++ but at the moment I'm
                        exploring the avenue of keeping it in C.
                        >
                        What's the best Big Number library for C? I need
                        to be able to represent the number (95 ^ 63), which
                        is approximately (2 ^ 6.6) ^ 63, which is about 2 ^
                        416, so we're talking about maybe a 512-Bit number.
                        <http://groups.google.c om/group/comp.lang.c/msg/696064e8b22a223 d>
                        So I need to be able to do division and multiplication
                        on a 512-Bit number.
                        Ah well in that case, add another 10 minutes onto the 2
                        spent implementing multiplication. :-)
                        Has anyone here had good experiences with a particular
                        Big Number library?
                        I've had good experiences with the simplest of primary
                        school algorithms.[1] In recent times, I only resort to
                        genuine bignum algorithms or libraries when the
                        calculation looks like taking days, not minutes.

                        Couple your code if you have to, but first determine
                        that you actually have to.

                        [1] Try calculating the 73 digit base 16 narcissistic
                        numbers, with or without a bignumb library.

                        --
                        Peter

                        Comment

                        • CBFalconer

                          #13
                          Re: Fully Portable Big Number Library

                          Ian Collins wrote:
                          vippstar@gmail. com wrote:
                          >Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
                          >>
                          .... snip ...
                          >>
                          >First of all, asking for advice on libraries here is off-topic.
                          >Your questions (and my answers) are:
                          >>
                          >>What's the best Big Number library for C?
                          >>
                          >Define best (your subject suggests 'fully portable' = 'best',
                          >however you don't mention it in the body of your article)
                          >>
                          >>Has anyone here had good experiences with a particular Big
                          >>Number library?
                          >>
                          >Yes
                          >
                          Well that was about as helpful as a fart in a wetsuit, wasn't it?
                          Which may be a great relief to the farter. :-) Define terms.

                          --
                          [mail]: Chuck F (cbfalconer at maineline dot net)
                          [page]: <http://cbfalconer.home .att.net>
                          Try the download section.

                          Comment

                          • CBFalconer

                            #14
                            Re: Fully Portable Big Number Library

                            Richard Harter wrote:
                            Richard Heathfield <rjh@see.sig.in validwrote:
                            .... snip ...
                            >>
                            >>First of all, asking for advice on libraries here is off-topic.
                            >>
                            >Why? It seems to me that the topic of this group is C programming,
                            >regardless of platform. Library usage is certainly a part of
                            >programming. Okay, I can understand - and agree - that detailed
                            >discussions on the usage of platform-specific libraries is off-
                            >topic here, but what he's asking for is a fully portable library.
                            >>
                            >I know of one reason why people might demur from helping the OP,
                            >but topicality isn't it.
                            >
                            Well said. In almost all other language groups, the focus is on
                            programming in that language. Naturally the details of the
                            language standard(s) (if any) are part of the discussion, but
                            they are not the entirety.
                            Well, the topic is portable C programming, as defined by the
                            standard. To me, this means libraries are topical, provided that
                            the library source is available, and primarily in standard C.
                            Queries about library availability seems quite topical too.

                            Observation: Big Number libraries do not require non-standard C.

                            --
                            [mail]: Chuck F (cbfalconer at maineline dot net)
                            [page]: <http://cbfalconer.home .att.net>
                            Try the download section.

                            Comment

                            • user923005

                              #15
                              Re: Fully Portable Big Number Library

                              On Oct 28, 2:51 pm, Peter Nilsson <ai...@acay.com .auwrote:
                              Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
                              >
                              I need a Big Number library. I've been considering
                              switching my project to C++ but at the moment I'm
                              exploring the avenue of keeping it in C.
                              >
                              What's the best Big Number library for C? I need
                              to be able to represent the number (95 ^ 63), which
                              is approximately (2 ^ 6.6) ^ 63, which is about 2 ^
                              416, so we're talking about maybe a 512-Bit number.
                              >
                              <http://groups.google.c om/group/comp.lang.c/msg/696064e8b22a223 d>
                              >
                              So I need to be able to do division and multiplication
                              on a 512-Bit number.
                              >
                              Ah well in that case, add another 10 minutes onto the 2
                              spent implementing multiplication. :-)
                              >
                              Has anyone here had good experiences with a particular
                              Big Number library?
                              >
                              I've had good experiences with the simplest of primary
                              school algorithms.[1] In recent times, I only resort to
                              genuine bignum algorithms or libraries when the
                              calculation looks like taking days, not minutes.
                              >
                              Couple your code if you have to, but first determine
                              that you actually have to.
                              >
                              [1] Try calculating the 73 digit base 16 narcissistic
                              numbers, with or without a bignumb library.

                              Comment

                              Working...