美文网首页
C++查看 IEEE 754 浮点数格式的代码

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

作者: gougoude | 来源:发表于2021-12-01 11:04 被阅读0次

把内容过程中较好的一些内容片段备份一次,下边资料是关于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;

}

相关文章

网友评论

      本文标题:C++查看 IEEE 754 浮点数格式的代码

      本文链接:https://www.haomeiwen.com/subject/cplsxrtx.html