Hexfloat机械手和精度

Ser*_*uin 3 c++ precision hex c++11

为什么使用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";

}
Run Code Online (Sandbox Code Playgroud)

尽管默认精度为6,但在以十六进制格式(coliru)(gcc 5.2.0)输出double时,这似乎会被忽略:

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
Run Code Online (Sandbox Code Playgroud)

是否可以使用十六进制格式确保小数精度为6?

Die*_*ühl 10

该std::hexfloat格式旨在转储浮点值的确切重复.字符串表示不是供人类使用,而主要是为了再次恢复完全相同的表示.因此,基于任何流设置以任何方式截断格式是没有意义的.