IA64与浮点数的IEEE标准不符?

时间:2013-05-01 23:20:20

标签: c++ floating-point ieee

我尝试使用此代码来表示浮点数存储系统:

float *f = new float();
int *i = new int();
i = reinterpret_cast<int *>(f);
std::bitset<32> *bs;

std::cin>>*f;
bs = new std::bitset<32>(*i);
std::cout<<*bs<<" == "<<*f<<std::endl;

但是当它以23.5运行时,结果为01000001-10111100-00000000-00000000。权力为10000001=63 由于IEEE标准,它不应该是64吗? 螳螂应该是00010111-10000000-00000000。这是真的吗?

注意:我用GCC和VS编译了这段代码。结果是一样的。

1 个答案:

答案 0 :(得分:8)

01000001-10111100-00000000-00000000

0 10000011 01111000000000000000000

sign: 0
exponent: 10000011_binary = 131_decimal
mantissa: 01111000000000000000000_binary
mantissa is defined by 1.<mantissa>
so -> 1.01111_binary

exponent is defined this way: exp-127
-> 131-127 = 4
-> 1.01111_binary * 2^4
-> comma shift to the right by 4 
--> 10111.1_binary = 23.5_decimal

通常:

(-1)^sign * 1.<mantissa> * 2^(exponent-127)