Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • ...that you're trying to move a long long between C and Perl. Do you need to do that? Can't the long longs just live inside the C?

    It's probably not too hard to write the code to thunk between long long and Math::BigInt - would that help?

    • I don't know since my C and XS skills are so poor. The relevant bit of XS code is this:

      #include "EXTERN.h"
      #include "perl.h"
      #include "XSUB.h"
      #include <stdbool.h>

      #include "ppport.h"

      /* This function calculates (ab)%c */
      int modulo(int a,int b,int c){
          long long x=1,y=a; // long long is taken to avoid overflow
                             // of intermediate results
          // skipping implementation

      /* this function calculates (a*b

      • If you're prepared to limit the input to 32 bit integers you can probably just change the long long to long in the prototype of Miller(). It should still use long long internally.

        To be more strictly correct you could use the output of

        perl -MConfig -le 'print $Config{ivtype}'

        as the type of that argument. That will be long for 32 bit Perl and long long for 64 bit Perl.

        And if you want to be really sneaky write a version that bypasses XS type mapping and correctly handles Math::BigInt objects :)

        • If you're prepared to limit the input to 32 bit integers
          A plain float in Perl has 53 bits of precision, which means you can represent 53 bit integers exactly, which is better than merely 32 bits.

          Or, am I missing a point?

          • No, I think you're quite right :)

            This little program:


            my $num  = 1;
            my $bits = 0;
            while ( $num + 1 != $num ) {
                $num *= 2;

            print "$bits\n";

            prints 53.

            So Ovid - make that argument a double and then cast it to a long long inside the function.