[libc-commits] [libc] [libc][NFC] Simplify logic in `sqrt` (PR #80426)
via libc-commits
libc-commits at lists.llvm.org
Fri Feb 2 05:47:10 PST 2024
================
@@ -43,20 +43,14 @@ LIBC_INLINE long double sqrt(long double x) {
LDBits bits(x);
- if (bits.is_inf_or_nan()) {
- if (bits.is_neg() && (bits.get_mantissa() == 0)) {
- // sqrt(-Inf) = NaN
- return LDNAN;
- } else {
- // sqrt(NaN) = NaN
- // sqrt(+Inf) = +Inf
- return x;
- }
- } else if (bits.is_zero()) {
+ if (bits == LDBits::inf(Sign::POS) || bits.is_zero()) {
+ // sqrt(+Inf) = +Inf
// sqrt(+0) = +0
// sqrt(-0) = -0
return x;
- } else if (bits.is_neg()) {
+ } else if (bits.is_inf_or_nan() || bits.is_neg()) {
----------------
lntue wrote:
This will change the NaN payload when `x` is NaN. When `x` is NaN we should return it as-is.
https://github.com/llvm/llvm-project/pull/80426
More information about the libc-commits
mailing list