[libc-commits] [libc] [libc][NFC] fix int warnings in float conversion (PR #74379)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Dec 4 14:40:15 PST 2023


================
@@ -157,9 +157,10 @@ LIBC_INLINE constexpr uint32_t ceil_log10_pow2(const uint32_t e) {
 LIBC_INLINE constexpr uint32_t length_for_num(const uint32_t idx,
                                               const uint32_t mantissa_width) {
   //+8 to round up when dividing by 9
-  return (ceil_log10_pow2(idx) + ceil_log10_pow2(mantissa_width + 1) +
-          (BLOCK_SIZE - 1)) /
-         BLOCK_SIZE;
+  return static_cast<uint32_t>((ceil_log10_pow2(idx) +
+                                ceil_log10_pow2(mantissa_width + 1) +
+                                (BLOCK_SIZE - 1)) /
+                               BLOCK_SIZE);
----------------
nickdesaulniers wrote:

I think just BLOCK_SIZE is a size_t which is resulting in promotions.  You could limit the static cast to just those (or perhaps define BLOCK_SIZE as a smaller type?)

https://github.com/llvm/llvm-project/pull/74379


More information about the libc-commits mailing list