4.2.6.13 Half-precision floating-point type [Professional Edition only] [V1.05.00 or later]

The half-precision floating-point type can be used.

The half-precision floating-point type has the following features.

-

The type name is __fp16.

-

The size is two bytes and the alignment condition is also two bytes.

-

The internal representation of data conforms to binary16 of IEEE754-2008.

-

The sign is one bit, the exponent is five bits, and the mantissa is 10 bits (11 bits when a hidden bit is included).

-

The bias of the exponent is 0xf. (Example: 1.0 is 0x3c00 in the hexadecimal notation.)

-

The only supported operations are assignment between __fp16 type values, type conversion from __fp16 to float, and type conversion from float to __fp16. Other operations are to be performed after data has been converted into the float type, and the result will have the same type as that for when performing the same operation for the float type. Similarly, type conversion from __fp16 to double is to be performed after data has been converted into the float type.

-

Denormal numbers are not supported for type conversion from float to __fp16, and they will be flushed to normal numbers in accordance with the rounding mode.

-

Only -Xround=nearest is available as the rounding mode.

-

There is no suffix for floating constants.

-

This type cannot be specified as the parameter type or return type of a function. To pass a value of the __fp16 type between functions, pass it by casting it to another type (e.g. float), by using a pointer, or by using a structure argument that has a member of the __fp16 type.

-

If the called function does not have a parameter typeNote, the value will be passed after the type is converted into float by default argument promotion and then further converted into double.

Note

This applies when there is no prototype declaration or parameter string, or there are a variable number of arguments.

-

If this type is specified for an argument, the value is passed after being converted into the parameter type. If there is no parameter type, the value will be passed after the type is converted into float by default argument promotion and then converted into double.

-

This type can be specified for a structure member, union member, or array element. This type cannot be specified for a bit field member.

 

Example

extern __fp16 hpvar1, hpvar2, hpvar3;
extern float fvar;
extern double dvar;
extern int ivar;
 
/* External variable definition */
__fp16 hpvar = 1.0;
 
void fun() {
  /* Constant assignment */
  hpvar = 1.0;
 
  /* Assignment to and from __fp16 */
  hpvar1 = hpvar2;
 
  /* Type conversion to single-precision floating-point number */
  fvar = hpvar;                                  /* Same as "fvar = (float)hpvar;" */
 
  /* Type conversion to double-precision floating-point number */
  dvar = hpvar;                          /* Same as "dvar = (double)(float)hpvar;" */
 
  /* Type conversion from double-precision floating-point number */
  hpvar = dvar;                          /* Same as "hpvar = (__fp16)(float)dvar;" */
 
  /* Type conversion to integer */
  ivar = hpvar;                             /* Same as "ivar = (int)(float)hpvar;" */
 
  /* Type conversion from integer */
  hpvar = ivar;                          /* Same as "hpvar = (__fp16)(float)ivar;" */
 
  /* Arithmetic operation */
  hpvar3 = hpvar1 + hpvar2;  /* Same as "hpvar3 = (__fp16)((float)hpvar1 + (float)hpvar2;)" */
}