Perl has long been my choice scripting language but I've run into a horrible problem. By default there is no support for long (64 bit) integers. Most of the time an integer is just a string and they work for seeking in huge files but there are plenty of places they don't work, such as binary &
, printf
, pack
, unpack
, <<
, >>
.
Now these do work in newer versions of Perl but only if it is built with 64-bit integer support, which does not help if I want to make portable code to run on Perls built without this option. And you don't always get control over the Perl on a system your code runs on.
My question is do Python, PHP, and Ruby suffer from such a problem, or do they also depend on version and build options?
A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
The long long data type makes handling 64 bit integers easy. In C language, an unsigned number over 32 bits cannot exceed the value of 4,294,967,295. You may find you are required to handle larger numbers and for this you need these numbers to be coded in 64-bit.
Several benchmarks show Lua as the fastest language in the realm of interpreted scripting languages. Lua is fast not only in fine-tuned benchmark programs, but in real life too. Substantial fractions of large applications have been written in Lua.
The size of high speed hardware integers (assuming the language has them) will always be dependent on whatever size integers are available to the compiler that compiled the language interpreter (usually C).
If you need cross-platform / cross-version big integer support, the Perl pragma use bigint;
will do the trick. If you need more control, bigint
is a wrapper around the module Math::BigInt
.
In the scope where use bigint;
is loaded, all of the integers in that scope will be transparently upgraded to Math::BigInt
numbers. Lastly, when using any sort of big number library, be sure to not use tricks like 9**9**9
to get infinity, because you might be waiting a while :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With