// Distributed under the Boost Software License Version 1.0 https://www.boost.org/LICENSE_1_0.txt // Copyright Gero Peterhoff // description // detect floating point with specified widths // detection table // MAX_EXP==16384 && MANT_DIG==113 -> float128 // MAX_EXP==16384 && MANT_DIG==64 -> float80 // MAX_EXP==1024 && MANT_DIG==53 -> float64 // MAX_EXP==128 && MANT_DIG==24 -> float32 // MAX_EXP==16 && MANT_DIG==11 -> float16 // MAX_EXP==128 && MANT_DIG==8 -> bfloat16 // https://www.heise.de/news/Gleitkommazahlen-im-Machine-Learning-Weniger-ist-mehr-fuer-Intel-Nvidia-und-ARM-7264714.html // not supported // MAX_EXP==16 && MANT_DIG==3 -> float8e5m2 // MAX_EXP==8 && MANT_DIG==4 -> float8e4m3 #ifndef BOOST_CSTDFLOAT_TYPES_HPP #define BOOST_CSTDFLOAT_TYPES_HPP #include #include namespace boost { #if (FLT_RADIX == 2) #if (LDBL_MAX_EXP==16384) && (LDBL_MANT_DIG==113) #define BOOST_L_IS_FLOAT128 #elif (LDBL_MAX_EXP==16384) && (LDBL_MANT_DIG==64) #define BOOST_L_IS_FLOAT80 #elif (LDBL_MAX_EXP==1024) && (LDBL_MANT_DIG==53) #define BOOST_L_IS_FLOAT64 #elif (LDBL_MAX_EXP==128) && (LDBL_MANT_DIG==24) #define BOOST_L_IS_FLOAT32 #elif (LDBL_MAX_EXP==16) && (LDBL_MANT_DIG==11) #define BOOST_L_IS_FLOAT16 #elif (LDBL_MAX_EXP==128) && (LDBL_MANT_DIG==8) #define BOOST_L_IS_BFLOAT16 #endif #if (DBL_MAX_EXP==16384) && (DBL_MANT_DIG==113) #define BOOST_D_IS_FLOAT128 #elif (DBL_MAX_EXP==16384) && (DBL_MANT_DIG==64) #define BOOST_D_IS_FLOAT80 #elif (DBL_MAX_EXP==1024) && (DBL_MANT_DIG==53) #define BOOST_D_IS_FLOAT64 #elif (DBL_MAX_EXP==128) && (DBL_MANT_DIG==24) #define BOOST_D_IS_FLOAT32 #elif (DBL_MAX_EXP==16) && (DBL_MANT_DIG==11) #define BOOST_D_IS_FLOAT16 #elif (DBL_MAX_EXP==128) && (DBL_MANT_DIG==8) #define BOOST_D_IS_BFLOAT16 #endif #if (FLT_MAX_EXP==16384) && (FLT_MANT_DIG==113) #define BOOST_F_IS_FLOAT128 #elif (FLT_MAX_EXP==16384) && (FLT_MANT_DIG==64) #define BOOST_F_IS_FLOAT80 #elif (FLT_MAX_EXP==1024) && (FLT_MANT_DIG==53) #define BOOST_F_IS_FLOAT64 #elif (FLT_MAX_EXP==128) && (FLT_MANT_DIG==24) #define BOOST_F_IS_FLOAT32 #elif (FLT_MAX_EXP==16) && (FLT_MANT_DIG==11) #define BOOST_F_IS_FLOAT16 #elif (FLT_MAX_EXP==128) && (FLT_MANT_DIG==8) #define BOOST_F_IS_BFLOAT16 #endif #endif // FLT_RADIX == 2 // float128 #if defined(BOOST_L_IS_FLOAT128) typedef long double float128_t; #define BOOST_FLOAT128_C(ARG) float128_t(ARG##L) #elif defined(BOOST_D_IS_FLOAT128) typedef double float128_t; #define BOOST_FLOAT128_C(ARG) float128_t(ARG) #elif defined(BOOST_F_IS_FLOAT128) typedef float float128_t; #define BOOST_FLOAT128_C(ARG) float128_t(ARG##F) #elif defined(BOOST_HAS_FLOAT128) typedef __float128 float128_t; #define BOOST_FLOAT128_C(ARG) float128_t(ARG##Q) #endif // float80 #if defined(BOOST_L_IS_FLOAT80) typedef long double float80_t; #define BOOST_FLOAT80_C(ARG) float80_t(ARG##L) #elif defined(BOOST_D_IS_FLOAT80) typedef double float80_t; #define BOOST_FLOAT80_C(ARG) float80_t(ARG) #elif defined(BOOST_F_IS_FLOAT80) typedef float float80_t; #define BOOST_FLOAT80_C(ARG) float80_t(ARG##F) #endif // float64 #if defined(BOOST_L_IS_FLOAT64) typedef long double float64_t; #define BOOST_FLOAT64_C(ARG) float64_t(ARG##L) #elif defined(BOOST_D_IS_FLOAT64) typedef double float64_t; #define BOOST_FLOAT64_C(ARG) float64_t(ARG) #elif defined(BOOST_F_IS_FLOAT64) typedef float float64_t; #define BOOST_FLOAT64_C(ARG) float64_t(ARG##F) #endif // float32 #if defined(BOOST_L_IS_FLOAT32) typedef long double float32_t; #define BOOST_FLOAT32_C(ARG) float32_t(ARG##L) #elif defined(BOOST_D_IS_FLOAT32) typedef double float32_t; #define BOOST_FLOAT32_C(ARG) float32_t(ARG) #elif defined(BOOST_F_IS_FLOAT32) typedef float float32_t; #define BOOST_FLOAT32_C(ARG) float32_t(ARG##F) #endif // float16 #if defined(BOOST_L_IS_FLOAT16) typedef long double float16_t; #define BOOST_FLOAT16_C(ARG) float16_t(ARG##L) #elif defined(BOOST_D_IS_FLOAT16) typedef double float16_t; #define BOOST_FLOAT16_C(ARG) float16_t(ARG) #elif defined(BOOST_F_IS_FLOAT16) typedef float float16_t; #define BOOST_FLOAT16_C(ARG) float16_t(ARG##F) #endif // bfloat16 #if defined(BOOST_L_IS_BFLOAT16) typedef long double bfloat16_t; #define BOOST_BFLOAT16_C(ARG) bfloat16_t(ARG##L) #elif defined(BOOST_D_IS_BFLOAT16) typedef double bfloat16_t; #define BOOST_BFLOAT16_C(ARG) bfloat16_t(ARG) #elif defined(BOOST_F_IS_BFLOAT16) typedef float bfloat16_t; #define BOOST_BFLOAT16_C(ARG) bfloat16_t(ARG##F) #endif #undef BOOST_L_IS_FLOAT128 #undef BOOST_D_IS_FLOAT128 #undef BOOST_F_IS_FLOAT128 #undef BOOST_L_IS_FLOAT80 #undef BOOST_D_IS_FLOAT80 #undef BOOST_F_IS_FLOAT80 #undef BOOST_L_IS_FLOAT64 #undef BOOST_D_IS_FLOAT64 #undef BOOST_F_IS_FLOAT64 #undef BOOST_L_IS_FLOAT32 #undef BOOST_D_IS_FLOAT32 #undef BOOST_F_IS_FLOAT32 #undef BOOST_L_IS_FLOAT16 #undef BOOST_D_IS_FLOAT16 #undef BOOST_F_IS_FLOAT16 #undef BOOST_L_IS_BFLOAT16 #undef BOOST_D_IS_BFLOAT16 #undef BOOST_F_IS_BFLOAT16 } // boost #endif // BOOST_CSTDFLOAT_TYPES_HPP