简体   繁体   中英

Java definition of infinity

I try to run this code in java

System.out.println(Math.pow(2,1024));
System.out.println(Math.pow(2,1023));

the results:

Infinity

8.98846567431158E307

I'm wondering - why 2^1024 is infinity? and 2^1023 isn't? I guess that there is a connection to the fact that 1024 is 2^10, but I don't really get it. Also, will the answer change if I will try to run it in a machine with 124 bit instead of 64 bit?

little confused, will appreciate any help :)

that is because the calculation goes outside of the double precision. You will see the same result in a "124" bit machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM