Keil Logo

RawF16ToF32

Summary
float    out = RawF16ToF32   (uint16_t in); /* returns a float value*/
Description

The RawF16ToF32 function converts a value from raw (binary representation) F16 to floating point format. As there is no native calculation possible for F16, this function converts the half float to float by calculating exponent and mantissa.

Note

Return Value

float

Example
FUNC unsigned long GetSReg(int idx)
{
  switch(idx) {
    case  0: return S0;
    case  1: return S1;
    case  2: return S2;
    case  3: return S3;
    case  4: return S4;
    case  5: return S5;
    case  6: return S6;
    case  7: return S7;
    case  8: return S8;
    case  9: return S9;
    case 10: return S10;
    case 11: return S11;
    case 12: return S12;
    case 13: return S13;
    case 14: return S14;
    case 15: return S15;
    case 16: return S16;
    case 17: return S17;
    case 18: return S18;
    case 19: return S19;
    case 20: return S20;
    case 21: return S21;
    case 22: return S22;
    case 23: return S23;
    case 24: return S24;
    case 25: return S25;
    case 26: return S26;
    case 27: return S27;
    case 28: return S28;
    case 29: return S29;
    case 30: return S30;
    case 31: return S31;
    default: return 0;
  }
}

FUNC void PrintAllFloat16()
{
  int i;
  unsigned long valU;
  unsigned short valU1, valU2;
  float valF1, valF2;

  for(i=0; i<32; i++) {
    valU = GetSReg(i);
    valU1 = (unsigned short)( valU        & 0xffff);
    valU2 = (unsigned short)((valU >> 16) & 0xffff);

    valF1 = RawF16ToF32(valU1);
    valF2 = RawF16ToF32(valU2);

    printf("S%i_LOW : %16x, --> %g\n", i, valU1, valF1);
    printf("S%i_HIGH: %16x, --> %g\n", i, valU2, valF2);
  }
}

  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.