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

I asked a question about manipulating 64-bit values. Elian and samtregar were kind enough to offer their responses. samtregar suggested using 5.8.0RC1. Because I don't want to force that version on users, I took Elian's suggestion of using 'use integer'.

That works pretty well, with a couple of exceptions. For one, hex() still uses floats, but that's pretty acceptable and easy to work around.. However, the kicker is that 'use integer' treats all values as signed. That causes problems when doing comparisons. For instance, 0x80000000000000000 will be less than 0x70000000000000000, because the highest bit is set.

I really need to convince perl to treat these as unsigned quantities. For now, I'm doing this by creating an "Address" class, and using operator overloading for "<=>" (and simple overloads for other mathematical operators). However, this is making the code much slower. (I'm dealing with these addresses a lot)

Is there any way I can convince perl to manipulate the values as (essentially) uint64_t's?

  • Comment on 'use integer;', or Manipulating 64-bit values, revisited

Replies are listed 'Best First'.
Re: 'use integer;', or Manipulating 64-bit values, revisited
by samtregar (Abbot) on Jun 07, 2002 at 00:59 UTC
    I don't know why this didn't occur to me before, but have you tried Math::BigInt? I think it should be just what you need to tide you over until you can switch to 5.8.0.

    -sam

Re: 'use integer;', or Manipulating 64-bit values, revisited
by Zaxo (Archbishop) on Jun 07, 2002 at 00:49 UTC

    The bitwise noop 0 | $foo normally forces unsignedness, but use integer; interferes with that, too.The no integer; pragma has lexical scope, so you can wrap it up in a bareblock with the unsigned operations.

    perl -Minteger -e'my $foo = 2**63-1 ; $foo = 2*$foo;print $foo,$/; { n +o integer; print 0|$foo,$/;}' -2 18446744073709551614

    After Compline,
    Zaxo