|Perl Monk, Perl Meditation|
Re^8: All Calculations Done with One Variable Give Integer Answersby syphilis (Chancellor)
|on Sep 24, 2013 at 04:57 UTC||Need Help??|
New code is up in the main post. I want to understand what's going on as well.
There's no problem with "use Math::BigInt;". It makes no difference whether that line is present or not.
What does the damage is "use Math::BigInt ':constant';" because that means all integer values are converted to Math::BigInt objects or, as the docs explain it:
Effectively, the math operations involving integers will be done using integer arithmetic - which is precisely as you have seen.
You can avoid this behaviour by simply not calling "use Math::BigInt ':constant';".
The only thing you then have to worry about is what happens when an integer value that is too big to fit into an IV comes along.
(perl -V:ivsize will tell you how many bytes your IV's can take up. It depends upon how perl was configured when it was being built and won't necessarily be the same on other builds of perl, even if they are the same version. Typically ivsize is either 4 or 8.)
If all of your integer values will fit into an IV, then there's little more to consider - just remove the offending line of code.