I have a _Float16
half-precision variable named x
in my C program, and would like to printf()
it. Now, I can write: printf("%f", (double) x);
, and this will work; but - can I printf x
directly? Without the cast, but rather with an appropriate format specifier?
Looking for an answer regarding glibc mostly, but other C standard library implementations are also interesting.
Note: _Float16
is not automatically promoted to a double
.
can I printf x directly?
Not out of the box.
I do not think https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3184.pdf was merged.
looking for an answer regarding glibc mostly
Implement https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html with strfromf16 .
Note that technically lowercase letters in printf format specifiers are reserved https://port70.net/~nsz/c/c11/n1570.html#7.31.11 . Consider uppercase letter, but no one cares. The C23 standard introduced upper case letters H D R K B
, so I do not understand how it works.
Note: _Float16 is not promoted to double in variadic argument list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With