C++ 六角浮动机械手与精度
为什么使用C++ 六角浮动机械手与精度,c++,c++11,hex,precision,C++,C++11,Hex,Precision,为什么使用hexfloat操纵器的输出会忽略ostream上的任何精度 #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main(){ cout << setw(17) << left << "default format: " << setw(20) << right &l
hexfloat
操纵器的输出会忽略ostream
上的任何精度
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
cout << setw(17) << left << "default format: " << setw(20) << right << 100 * sqrt(2.0) << " " << cout.precision() << '\n'
<< setw(17) << left << "scientific: " << setw(20) << right << scientific << 100 * sqrt(2.0) << " " << cout.precision() << '\n'
<< setw(17) << left << "fixed decimal: " << fixed << setw(20) << right << 100 * sqrt(2.0) << " " << cout.precision() << '\n'
<< setw(17) << left << "hexadecimal: " << hexfloat << setw(20) << right << uppercase << 100 * sqrt(2.0) << nouppercase << " " << cout.precision() << '\n'
<< setw(17) << left << "use defaults: " << defaultfloat << setw(20) << right << 100 * sqrt(2.0) << " " << cout.precision() << "\n\n";
}
是否可以使用十六进制格式确保十进制精度为6?标准::hexfloat格式旨在转储浮点值的精确重复。字符串表示不是供人使用的,而是主要用于再次恢复完全相同的表示。因此,基于任何流设置以任何方式截断格式是没有意义的。请参阅。
default format: 141.421 6
scientific: 1.414214e+02 6
fixed decimal: 141.421356 6
hexadecimal: 0X1.1AD7BC01366B8P+7 6
use defaults: 141.421 6