If you want to use any of the functions from the C standard library on the _Float16
data type, then you must manually cast the _Float16
value to a single-precision, or double-precision value, and then use the appropriate library function.
Also, the library function printf
does not have a string format specifier for the _Float16
data type. Therefore an explicit cast is required for the _Float16
data type. The following example casts the _Float16
value to a double
for use in the printf
function.
// foo.c
#include <stdlib.h>
#include <stdio.h>
_Float16 foo(void)
{
_Float16 n = 1.0f16;
// Cast the _Float16 value n to a double because there is no string format specifier for half-precision floating-point values.
printf ("Hello World %f \n", (double)n);
return n;
}
To compile this example with armclang
, use the command:
armclang --target=arm-arm-none-eabi -march=armv8.2-a+fp16 -std=c90 -c foo.c -o foo.o
The printf
function does not automatically cast the
_Float16
value. If you do not manually cast the
_Float16
value, armclang
produces the
-Wformat
diagnostic message.
warning: format specifies type 'double' but the argument has type '_Float16' [-Wformat]
printf ("Hello World %f\n", n);