简体   繁体   English

为什么我的64位计算机不能在C ++中存储双精度数2 ^ 1024?

[英]Why can't my 64-bit computer store the double-precision number 2^1024 in C++?

My computer has an Intel® Core™2 Duo Processor, which I believe is a 64-bit processor. 我的计算机装有Intel®Core™2 Duo处理器,我相信它是64位处理器。 So I had thought that in C++ (or any other programming language), any double-precision number (which requires 64 bits) could be stored. 所以我以为在C ++(或任何其他编程语言)中,可以存储任何双精度数字(需要64位)。

I read the following link: http://en.wikipedia.org/wiki/Double-precision_floating-point_format 我阅读了以下链接: http : //en.wikipedia.org/wiki/Double-precision_floating-point_format

Based on that, I know that a double-precision number has 1 bit for the sign, 11 bits for the exponent, and the remaining 52 bits for the fraction. 基于此,我知道双精度数的符号为1位,指数为11位,其余为小数位52位。

So, I thought I'd experiment with a double that has the following binary code: 因此,我认为我将尝试使用具有以下二进制代码的double:

0 11111111111 0000000000000000000000000000000000000000000000000000 0 11111111111 0000000000000000000000000000000000000000000000000000000000

Again, based on what I read in the above link, I think this number translates to a decimal number of 2^1024, the exponenent being equal to the following: 同样,根据我在上面的链接中所读的内容,我认为该数字转换为十进制数字2 ^ 1024,指数等于以下值:

2^10 + 2^9 + 2^8 + 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 - 1023 2 ^ 10 + 2 ^ 9 + 2 ^ 8 + 2 ^ 7 + 2 ^ 6 + 2 ^ 5 + 2 ^ 4 + 2 ^ 3 + 2 ^ 2 + 2 ^ 1 + 2 ^ 0-1023

I then tried to print 2^1024 in C++, using the following code: 然后,我尝试使用以下代码在C ++中打印2 ^ 1024:

double x = pow(2.0, 1024);
cout << x << endl;

However, when I run the program, it prints '1.#INF' 但是,当我运行该程序时,它会显示“ 1.#INF”

Does anyone know why? 有人知道为什么吗?

Some bit patters are reserved for special use like not-a-number, +infinity and -infinity. 一些位模式保留给特殊用途,例如非数字,+无限和-无限。 You have encountered the one used for +infinity. 您遇到了用于+ infinity的那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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