[llvm] [APInt] Provide isqrt (floor of square root) instead of sqrt (rounded) (PR #197406)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 05:03:47 PDT 2026
================
@@ -1809,8 +1809,8 @@ class [[nodiscard]] APInt {
return logBase2();
}
- /// Compute the square root.
- LLVM_ABI APInt sqrt() const;
+ /// Compute the floor of the square root of the unsigned value.
+ LLVM_ABI APInt isqrt() const;
----------------
jayfoad wrote:
I guess any those names would be fine.
I did look at https://gmplib.org/manual/Integer-Roots for inspiration. It just uses the name `mpz_sqrt` for "the truncated integer part of the square root". (This further convinces me that the truncating behaviour is the only behaviour worth implementing.)
https://github.com/llvm/llvm-project/pull/197406
More information about the llvm-commits
mailing list