Java results differ for (int)Math.pow(2,x) and 1<<x

前端 未结 5 1944
忘掉有多难
忘掉有多难 2020-12-31 17:21

Why do the following two operations yield different results in Java for x = 31 or 32 but the same results for x=3?

int         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 17:26

    Consider the limits of the type int. How large a number can it hold?

提交回复
热议问题