I have created my own personal data structure libraries for C and I've re-engineered it about two times now and I've added alot of preprocessor checks and defines concerning OS type and compiler type.
One thing I've wanted to add to my personal libraries is having an informal "standard" fixed-size floating-point types.
#ifndef __float32_t_defined
# if defined(COMPILER_CLANG) || defined(COMPILER_GCC)
# define __float32_t_defined
typedef float float32_t TYPE_MODE(__SF__);
# elif FLT_MANT_DIG==24
# define __float32_t_defined
typedef float float32_t;
# elif DBL_MANT_DIG==24
# define __float32_t_defined
typedef double float32_t;
# endif
#endif
#ifndef __float64_t_defined
# if defined(COMPILER_CLANG) || defined(COMPILER_GCC)
# define __float64_t_defined
typedef float float64_t TYPE_MODE(__DF__);
# elif FLT_MANT_DIG==53
# define __float64_t_defined
typedef float float64_t;
# elif DBL_MANT_DIG==53
# define __float64_t_defined
typedef double float64_t;
# elif LDBL_MANT_DIG==53
# define __float64_t_defined
typedef long double float64_t;
# endif
#endif
#ifndef __floatmax_t_defined
# if defined(COMPILER_CLANG) || defined(COMPILER_GCC)
# define __floatmax_t_defined
typedef double floatmax_t TYPE_MODE(__XF__);
# elif LDBL_MANT_DIG>=64
# define __floatmax_t_defined
typedef long double floatmax_t;
# elif DBL_MANT_DIG>=64
# define __floatmax_t_defined
typedef double floatmax_t;
# else
# define __floatmax_t_defined
typedef float floatmax_t;
# endif
#endif
For Clang and GCC, I use the compiler extension that checks machine mode and sets the type definition to the largest width of the floating point type. I added further type definition checks in the event Clang or GCC are not used.
my main question is that, given the macros in float.h
, is checking float size by its mantissa a wise/safe thing to do? If not, what alternative can I take?
float32_t
, a 64-bitfloat64_t
regardless of their internal proprieties? \$\endgroup\$floatmax_t
? \$\endgroup\$float32_t
andfloat64_t
is that those types are always their fixed size. The goal offloatmax_t
is to be the largest float width possible, which might either be the same asfloat32_t
, orfloat64_t
, or even higher than those two. \$\endgroup\$