[PATCH] math: fix Wshift-overflow warning.
Collin Funk
collin.funk1@gmail.com
Mon Sep 22 05:25:46 GMT 2025
When compiling on x86_64 with -Wshift-overflow=2 you can see the
following warning:
../sysdeps/ieee754/flt-32/math_config.h: In function ‘is_inf’:
../sysdeps/ieee754/flt-32/math_config.h:184:37: warning: result of ‘2139095040 << 1’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Wshift-overflow=]
184 | return (x << 1) == (EXPONENT_MASK << 1);
| ^~
This patch adjusts the definitions to use UINT32_C. This matches the
definitions in sysdeps/ieee754/dbl-64/math_config.h which use UINT64_C
for these definitions.
---
sysdeps/ieee754/flt-32/math_config.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h
index 33ea631d5f..6bb5c3324c 100644
--- a/sysdeps/ieee754/flt-32/math_config.h
+++ b/sysdeps/ieee754/flt-32/math_config.h
@@ -166,11 +166,11 @@ issignalingf_inline (float x)
#define MANTISSA_WIDTH 23
#define EXPONENT_WIDTH 8
#define EXPONENT_BIAS 127
-#define MANTISSA_MASK 0x007fffff
-#define EXPONENT_MASK 0x7f800000
-#define EXP_MANT_MASK 0x7fffffff
-#define QUIET_NAN_MASK 0x00400000
-#define SIGN_MASK 0x80000000
+#define MANTISSA_MASK UINT32_C (0x007fffff)
+#define EXPONENT_MASK UINT32_C (0x7f800000)
+#define EXP_MANT_MASK UINT32_C (0x7fffffff)
+#define QUIET_NAN_MASK UINT32_C (0x00400000)
+#define SIGN_MASK UINT32_C (0x80000000)
static inline bool
is_nan (uint32_t x)
--
2.51.0
More information about the Libc-alpha
mailing list