sfactor sfactor - 1 year ago 75
Perl Question

Performing math operations on very large numbers in Perl

I have a case where some values in a data file have 64 bit wrap around which makes them very large, like,


So I have to perform a subtraction from 2^64. I tried this using the simple

2^64 - 18446744073709551608

But I guess this number is too large and don't get the actual answer 8. What do I need to do to perform this substraction.

Answer Source

Check out the bignum pragma:

use bignum;

print 2**64 - 18446744073709551608;

This should properly print 8.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download