如果我在 bash(4.0.33(0)-release) 中使用大于 62 的整数作为 2 的幂,则会发生以下情况:
$ time echo $((2**60))
1152921504606846976
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ time echo $((2**61))
2305843009213693952
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ time echo $((2**62))
4611686018427387904
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ time echo $((2**63))
-9223372036854775808
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ time echo $((2**64))
0
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ time echo $((2**65))
0
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$
我猜这与二进制补码有关?但是,有人可以更详细地解释为什么 bash 的行为方式如此吗?