__float128
is a vendor extension.
In C23, _FloatN
for N = 16, 32, 64, 128
or multiples of 32 greater than 128 are standardised extensions that a compiler can provide. So _Float128
would be the standard type. To print the type, you use strfromfN
to turn it into a string:
void print(_Float128 fp) {
char buf[32 + sizeof(".e+99999")];
int sz = strfromf128(buf, sizeof buf, "%.32g", fp);
fwrite(buf, 1, sz, stdout);
}
https://godbolt.org/z/E7W6a4r8d
In C++23, as well as _FloatN
probably being provided as well by your compilers as an extension, std::float128_t
is provided as the standard 128-bit float type.
It is implementation defined if there is an overload for operator<<
so you can simply use std::cout
, but there will be a std::formatter
specialization, so std::format
can be used to create a string:
void print(std::float128_t fp) {
std::println("{:.32g}", fp); // std::println is C++26
// C++23: `std::cout << std::format("{:.32g}\n", fp);`
}
https://godbolt.org/z/5sahahn4P
Before C23/C++23, there was no standard type for 128 bit float. Sometimes long double
is 128 bits, but that is rare (it is more likely to be 80 bits or the same 64 bits as a regular double
). So you had to use compiler extensions or a software emulation library.