FuturistCorporation
July 22nd, 2011, 09:22 PM
I am doing arithmetic operations in the shell, just to try it out, and I was confused by the output I got for one operation:
If you input:
echo $((2**62))
You get 4611686018427387904, which is correct. But, if you input
echo $((2**63))
You get -9223372036854775808, which would be correct, EXCEPT THE VALUE IS NEGATIVE! Why did this happen?
Furthermore, if you input any value higher than this, i.e.,
echo $((2**64))
You get a value of 0, (rather than a memory error or something). Can anyone explain this to me?? I'm assuming the wrong answer on the last operation has something to do with UTF-8 character encoding (possibly?). But the negative value for $((2**63)) is what I really can't get my head around. Thoughts?
If you input:
echo $((2**62))
You get 4611686018427387904, which is correct. But, if you input
echo $((2**63))
You get -9223372036854775808, which would be correct, EXCEPT THE VALUE IS NEGATIVE! Why did this happen?
Furthermore, if you input any value higher than this, i.e.,
echo $((2**64))
You get a value of 0, (rather than a memory error or something). Can anyone explain this to me?? I'm assuming the wrong answer on the last operation has something to do with UTF-8 character encoding (possibly?). But the negative value for $((2**63)) is what I really can't get my head around. Thoughts?