I am a perl newbie,
Can I simply use 64-bit arithmetic in Perl?
For example
$operand1 = 0xFFFFFFFFFFFF; # 48 bit value
$operand2 = 0xFFFFFFFFFFFF; # 48 bit value
$Result = $operand1 * $operand2;
- I am basically looking for a replacement for the int64_t in perl.
- Is there any way to mention, if the variable is signed or unsigned?
Yes, however you need to have Perl compiled with 64-bit support.
use bigint
will make Perl handle arbitrary size integers correctly without integer overflow.Eg.:
will print:
Yes, Perl automatically handles large integer arithmetic for you. However, Perl does not offer a distinction between signed and unsigned types (there's no need, since there are not fixed bounds on large integer range).
The perlnumber manual page has more information about the different numeric formats supported by Perl.
Be aware, 64bit arithmetic in Perl is one, but what it is displayed by sprintf %d %u and %s, is second. Current perl version supports 64bits without problems, but sprintf %d format not, %b likewise .
See bigint: