Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Module for 128-bit integer math?

by BrowserUk (Patriarch)
on Feb 06, 2011 at 08:46 UTC ( [id://886488]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

I thought I remembered seeing a module that provided 128-bit integer math, but my searches have turned nothing up. Did I imagine it, or does it exist somewhere?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: Module for 128-bit integer math?
by ambrus (Abbot) on Feb 06, 2011 at 13:08 UTC

    May I ask out of curiosity what you would like to use those integers for? Eg. block cyphers, message digests, graphics, physical modeling, amounts of money?

    What seems strange to me is that you want more performance than you can get using any of the generic big integer modules, yet you still want to do individual integer operations in perl, as opposed to using higher level functions written in C, such as a cryptographic library or a library for numerical vectors.

    For reference to visitors, some (but not all) arbitrary precision integer libraries on CPAN are the two fast backends of Math::BigInt (Math::BigInt::GMP and Math::BigInt::Pari), Math::GMP, Math::GMPz, Math::Pari. I believe that none of the integer vector modules support 128 bit integers: PDL just doesn't, whereas Math::GSL wraps C libraries (GSL and indirectly BLAS) which only support real and complex floating point vectors.

    Update 2011-03-18: continuing the list of arbitrary precision arithmetic solutions, see also Convert big number from decimal to hexadecimal.

      You have a problem with me asking if such a module is available?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Some of us do suffer from curiosity. Show us only the tusk, and our minds become restless trying to fathom the nature and purpose of the beast.
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Module for 128-bit integer math?
by Corion (Patriarch) on Feb 06, 2011 at 09:17 UTC

    There is Math::BigInt, but I guess it's not as optimized for 128-bit integer math as you would like.

Re: Module for 128-bit integer math?
by Khen1950fx (Canon) on Feb 06, 2011 at 11:29 UTC

      Thanks, but no. I'm trying to avoid the overhead of arbitrary precision.

      My 64-bit processor has 128-bit math capabilities in hardware and I like to use them. I really thought I'd seen a module that did that, but maybe I'll have to write it myself. Or at least wrap one of the C libs that do it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        ... maybe I'll have to write it myself

        I think so. I've not noticed anything geared to 128-bit hardware capabilities.

        I'd encourage you to consider making it public - either as a module on CPAN, or just as a Cool Uses For Perl submission.

        Cheers,
        Rob
        Or at least wrap one of the C libs that do it.

        Have you found any 128bit math library in good shape? I have been googling for a while and all I have found is very rudimentary. Nothing complete or exploiting the 128bit abilities of modern processors.

        gcc seems to have some basic support also, but the documentation about that feature is very poor and does not even state the processors where it is supported.

        Well, the thing is that if you are able to find some good 128bits library, building a Math::Int128 module using Math::Int64 as a base should be pretty straight forward. Just point me to the library and I will do it!

        BTW, I would also like to see a 256bits module... even if at that size, the performance would be pretty similar to that of a bigint library operating over integers of the same size.

        You could try to go down the interesting route of compiling a Perl with an IV size of 128 bit, but that'll likely make the XS libraries crash and burn as they likely suppose that sizeof(void *) == sizeof(int) == sizeof(IV). But it might be worth a try to just see whether Perl compiles and tests OK with an enlarged IV.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://886488]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found