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

use Perl Log In

Log In

[ Create a new account ]

davorg (18)

Yahoo! ID: daveorguk (Add User, Send Message)

Hacker, author, trainer

Technorati Profile []

Journal of davorg (18)

Tuesday October 23, 2007
09:36 AM

One Of These Things Is Not Like The Others

[ #34739 ]

This was brought up in a discussion at work today. Spot the odd one out.

SQL> select BITAND(1798729892926983663,268435455) from dual;

-------------------------------- -----

$ python
>>> 1798729892926983663 & 268435455

$ ruby
print 1798729892926983663 & 268435455

$ perl -le 'print 1798729892926983663 & 268435455'

Of course, you can always use:

$ perl -Mbignum -le 'print 1798729892926983663 & 268435455'

But it's a bit embarassing that it doesn't Just Work.

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.
  • FWIW this also works fine when 64-bit ints are compiled in -- which IMO should be the default whenever it's available.
    • Oh, I hadn't thought of that. I wonder if it's just that Perl hasn't been built with 64-bit support but the others have.
      • No, it is not how the language is compiled.

        Ruby borrowed an idea from Smalltalk. Small integers are of type Fixnum, and it automatically promotes results above about a billion to Bignum on the fly. (IIRC, it has to reserve one bit for the sign and one for some internal bookkeeping.) As a result integer operations with Ruby are always exact. There is some overhead for this scheme, but there are tricks that make it less than you think. (Again, these tricks were worked out for Smalltalk.)

        Given that Python
  • I did wonder how hard it'd be to make Perl's numbers use the equivalent of bignum/bigfloat internally...
  • Works for me on a 10+ year old system with the default perl.

    wdr@tropo:~$ perl -le 'print 1798729892926983663 & 268435455'

    Of course, I cheat a little ...

    wdr@tropo:~$  perl -MConfig -le 'print "$_:$Config{$_}" for sort grep /use64/, keys %Config'

    wdr@tropo:~$ perl -v | head -2

    This is perl, v5.8.4 built for alpha-linux-thread-multi

    DEC Alpha was born 64bit pure, so Debian installs Perl 64bit on Alpha.

    # I had a sig when sigs were cool
    use Sig;