[libc-commits] [libc] [libc][stdfix][NFC] Use cpp::numeric_limits<T>::digits in divifx (PR #239900)

Jaeyong Lee via libc-commits libc-commits at lists.llvm.org
Sun Nov 8 17:33:54 PST 2026


npmania wrote:

Yes, because `numeric_limits<IntType>::digits` equals `sizeof(IntType) * 8 - cpp::is_signed_v<IntType>`.

For the INTERMEDIATE_BITS <= 64 part, unsigned cases are unchanged where `numeric_limits<uint64_t>::digits == 64` and signed cases:

```
divik  / divir  -> 31 + 15 = 46 <= 63 or 64
divilk / divilr -> 63 + 31 = 94 >  63 or 64 (LP64)
divilk / divilr -> 31 + 31 = 62 <= 63 or 64 (ILP32)
```

The original code has only been safe because no signed combination hits the hardcoded 64 exactly.

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


More information about the libc-commits mailing list