C++查看 IEEE 754 浮点数格式的代码

把内容过程中较好的一些内容片段备份一次,下边资料是关于C++查看 IEEE 754 浮点数格式的内容。

for binary floating-point numbers (IEEE 754) is to use a union, as shown in the following example:

#include <iostream>

#include <basetsd.h>

#include <iomanip>

#include <cstdlib>

using namespace std;

{

}fn;

union DoubleNum

{

}dn;

union LongDoubleNum

{

}ldn;

int main()

{

    cout << "nsize of float = " << dec << sizeof(fn.fx) << endl;

    cout << setprecision(10) << fn.fx << " = 0x" << hex << fn.lx << endl;

    cout << "nsize of double = " << dec << sizeof(dn.dx) << endl;

    cout << dn.dx <<"  = 0x" << hex << dn.lx << endl;

    cout << "nsize of long double = " << dec << sizeof(ldn.dx) << endl;

    cout << setprecision(10) << ldn.dx << " = 0x" << hex << ldn.lx[2] << ldn.lx[1] << ldn.lx[0] << endl;

    return 0;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容