Closed MisterDA closed 1 year ago
This warning is generated by clang 14.
warning: floating-point comparison is always false; constant cannot be represented exactly in type float [-Wliteral-range]
Use float instead of double constants.
#include <stdio.h> typedef float x; typedef double y; typedef int z; #define IS_FLOAT_FLOAT ((float)((x)1.23) == 1.23) // warning, 0, incorrect! #define IS_FLOAT_FLOAT_F ((float)((x)1.23f) == 1.23f) // 1 #define IS_DOUBLE_FLOAT ((float)((y)1.23) == 1.23) // warning, 0 #define IS_DOUBLE_FLOAT_F ((float)((y)1.23f) == 1.23f) // 1 #define IS_INT_FLOAT ((float)((z)1.23) == 1.23) // warning, 0 #define IS_INT_FLOAT_F ((float)((z)1.23f) == 1.23f) // 0 int main(void) { printf("IS_FLOAT_FLOAT: %d\nIS_FLOAT_FLOAT_F: %d\nIS_DOUBLE_FLOAT: %d\n" "IS_DOUBLE_FLOAT_F: %d\nIS_INT_FLOAT: %d\nIS_INT_FLOAT_F: %d\n", IS_FLOAT_FLOAT, IS_FLOAT_FLOAT_F, IS_DOUBLE_FLOAT, IS_DOUBLE_FLOAT_F, IS_INT_FLOAT, IS_INT_FLOAT_F); }
Thanks!
This warning is generated by clang 14.
Use float instead of double constants.