Search code examples
cfloating-pointsignal-processingstm32

Floating point number notation in C language


Whati is p in const float Q31_MAX_F = 0x0.FFFFFFp0F;? Generally what is a, b and c in 0xa.bpc?

Does this expression explicitely define binary stored in float32_t?

I have serached for it in web but doesn't find anything.


Solution

  • The F at the end of 0x0.FFFFFFp0F makes this interesting.


    What is p in const float Q31_MAX_F = 0x0.FFFFFFp0F;?

    p is the exponential indicator for some floating point hexadecimal * 2decimal power of 2.

    It is 0x0.FFFFFF * pdecimal power of 2, not some hexadecimal exponent 0F.

    F at the end of 0x0.FFFFFFp0F (more commonly an f) indicates the constant is a float and not a double. The F is not part of the exponent. The value is 0x0.FFFFFF*pow(2,0) or exactly 0.999999940395355224609375


    Generally what is a, b and c in 0xa.bpc?

    With 0x0.FFFFFFp0F, a is 0, b is the hexadecimal fraction 0.FFFFFF or 16,777,215/16,777,216 or 0.999999940395355224609375 and c is 0.


    Does this expression explicitly define binary stored in float32_t?

    With an F or f suffix, 0x0.FFFFFFp0F is a constant of type float.

    float32_t is not a standard C type.