我想打印常量 e,但我很快意识到,cout 无法处理 __float128。由于该函数无法打印 __float 128 。我还尝试了一些可以在网上找到的解决方案,它们都告诉我将其转换为双精度。但这会失去计算的精度。
我使用的是 GCC x64。
C++23 将 to_chars API 更改为:
std::to_chars - cppreference.com
std::to_chars_result to_chars( char* first, char* last, /* floating-point-type */ value, std::chars_format fmt, int precision );
(C++23 起)
看来有办法。
__float128 x = 1.123456789012345678901l;
char buffer[256];
std::to_chars(std::begin(buffer), std::end(buffer), x);
std::cout << buffer;
https://godbolt.org/z/sKdKxYKdG
但首先我会在使用之前对其进行公平的测试。