if(x>-2147483648&&x<2147483647). However , There are obviously two things wrong here .(1) How do you calculate in a short time 2^ 31？(2) because x yes int type , Even if x overflow , Due to storage limitations , that x The value of must also be within this range ( Type upgrade is not considered here ). So this judgment is unscientific .
See here , Although I know, I don’t know how to judge , Xiaobai asks for an answer , Enter a number to judge whether it overflows. How can I judge , Especially above （2）
2 Of 31 Power doesn’t have to be calculated ,long a = 0x7FFFFFFF Namely 2 Of 31 Power
Read more here: Source link