|
Math::Int64 - Manipulate 64 bits integers in Perl |
Math::Int64 - Manipulate 64 bits integers in Perl
use Math::Int64 qw(int64);
my $i = int64(1);
my $j = $i << 40;
my $k = int64("12345678901234567890");
print($i + $j * 1000000);
This module adds support for 64 bit integers, signed and unsigned, to Perl.
int64()int64($value)$value, where
$value can be a Perl number or a string containing a number.
For instance:
$i = int64(34);
$j = int64("-123454321234543212345");
$k = int64(1234567698478483938988988); # wrong!!!
# the unquoted number would
# be converted first to a
# real number causing it to
# loose some precision.
Once the int64 number is created it can be manipulated as any other Perl value supporting all the standard operations (addition, negation, multiplication, postincrement, etc.).
net_to_int64($str)int64_to_net($int64)native_to_int64($str)int64_to_native($int64)int64_to_number($int64)For instance:
for my $l (10, 20, 30, 40, 50, 60) {
my $i = int64(1) << $l;
my $n = int64_to_number($i);
print "int64:$i => perl:$n\n";
}
At this moment, this module requires int64 support from the C compiler. Also, it doesn't take any advantage of perls with 64 bit IVs.
For bug reports, feature requests or just help using this module, use the RT system at http://rt.cpan.org or send my and email or both!
Other modules that allow Perl to support larger integers or numbers are the Math::BigInt manpage, the Math::BigRat manpage and the Math::Big manpage, the Math::BigInt::BitVect manpage, the Math::BigInt::Pari manpage and the Math::BigInt::GMP manpage.
Salvador Fandiño, <sfandino@yahoo.com>
Copyright (C) 2007 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
|
Math::Int64 - Manipulate 64 bits integers in Perl |