in reply to math problems

You are likely having a problem with hitting the upper limit of signed native integers. For example, printf '%020d', 2**31; outputs -0000000002147483648 on my 32-bit MS machine and printf '%020d', 2**63; ouptuts -9223372036854775808 on my 64-bit Linux box.

I would also comment that when you are asking folks to diagnose a problem with a specific input file, providing that input (wrapped in code tags) can be very helpful.