[libc-commits] [libc] [libc][stdfix][NFC] Use cpp::numeric_limits<T>::digits in divifx (PR #239900)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 6 21:44:10 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Jaeyong Lee (npmania)
<details>
<summary>Changes</summary>
Use `cpp::numeric_limits<T>::digits` in `divifx` to count value bits instead of `sizeof(IntType) * 8 - cpp::is_signed_v<IntType>`.
Also compare `INTERMEDIATE_BITS` against `cpp::numeric_limits<int64_t>::digits` (63) instead of `64` for signed types, since `INTERMEDIATE_BITS` excludes the sign bit.
Follows https://github.com/llvm/llvm-project/pull/235602#issuecomment-6417638445.
---
Full diff: https://github.com/llvm/llvm-project/pull/239900.diff
1 Files Affected:
- (modified) libc/src/__support/fixed_point/fx_bits.h (+7-4)
``````````diff
diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 47798d0f6730ab..eb7af96aa7c993 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -390,13 +390,16 @@ divifx(IntType n, FXType d) {
constexpr int F = FXRep::FRACTION_LEN;
- constexpr int INTERMEDIATE_BITS =
- sizeof(IntType) * 8 - cpp::is_signed_v<IntType> + F;
+ constexpr int INTERMEDIATE_BITS = cpp::numeric_limits<IntType>::digits + F;
using WideType = cpp::conditional_t<
cpp::is_signed_v<IntType>,
- cpp::conditional_t<INTERMEDIATE_BITS <= 64, int64_t, Int128>,
- cpp::conditional_t<INTERMEDIATE_BITS <= 64, uint64_t, UInt128>>;
+ cpp::conditional_t<INTERMEDIATE_BITS <=
+ cpp::numeric_limits<int64_t>::digits,
+ int64_t, Int128>,
+ cpp::conditional_t<INTERMEDIATE_BITS <=
+ cpp::numeric_limits<uint64_t>::digits,
+ uint64_t, UInt128>>;
WideType scaled_n = static_cast<WideType>(n) << F;
WideType result = scaled_n / static_cast<WideType>(d_comp);
``````````
</details>
https://github.com/llvm/llvm-project/pull/239900
More information about the libc-commits
mailing list