Search code examples
ctypesfloating-pointdecimal

How many floating-point types are there in C?


As many programmers know there are several floating-point types in C. So far I know float, double and long double but I'm not quite sure they are all of them, cause I found several definitions like __DEC32_MAX__. At first I thought that is another name for __FLT_MAX__ but when I tried to print it, I realized that it's different (as in below):

#include <stdio.h>

void main(void)
{
    __mingw_printf("flt    value: %e, size: %d\n", __FLT_MAX__, sizeof(__FLT_MAX__));
    __mingw_printf("dbl    value: %e, size: %d\n", __DBL_MAX__, sizeof(__DBL_MAX__));
    __mingw_printf("ldbl   value: %e, size: %d\n", __LDBL_MAX__, sizeof(__LDBL_MAX__));
    __mingw_printf("dec32  value: %e, size: %d\n", __DEC32_MAX__, sizeof(__DEC32_MAX__));
    __mingw_printf("dec64  value: %e, size: %d\n", __DEC64_MAX__, sizeof(__DEC64_MAX__));
    __mingw_printf("dec128 value: %e, size: %d\n", __DEC128_MAX__, sizeof(__DEC128_MAX__));
}

/* output:
flt    value: 3.402823e+038, size: 4
dbl    value: 1.797693e+308, size: 8
ldbl   value: 3.237664e-317, size: 16
dec32  value: 9.944455e-315, size: 4
dec64  value: 9.089022e+269, size: 8
dec128 value: 3.237656e-317, size: 16
*/

What are __DEC__* s?
Are there any other floating-point types that I don't know?


Solution

  • Some specific uses require small floats like: float8 and float16 and bifloat It is used mainly in the DSP, AI and graphics applications. Many hardware architectures support at least some of them (for example bifloat AVX-512 BF16, ARM-V8.8, AMD ROCm, CUDA and some more).

    There are also big float formats like float128. Example hardware: VSX in PowerPC.

    Those floats are not supported directly by the standard C. Some compilers support it as an extension.