Keil Logo

Library support for _Float16 data type

6.7 Library support for _Float16 data type

The C standard library in Arm® Compiler 6 does not support the _Float16 data type.

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);
Non-ConfidentialPDF file icon PDF version100067_0612_00_en
Copyright © 2014–2019 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.