From patchwork Sun Jan 18 17:47:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 128435 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 1AA964BA2E3D for ; Sun, 18 Jan 2026 17:52:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AA964BA2E3D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=aurel32.net header.i=@aurel32.net header.a=rsa-sha256 header.s=202004.hall header.b=uT3aoo5B X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id E5C1C4BA2E2D for ; Sun, 18 Jan 2026 17:52:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5C1C4BA2E2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aurel32.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5C1C4BA2E2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:bc8:30d7:100::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768758746; cv=none; b=wMuXLAXmjTMBRvU4NyhiogpM+aiU4YM9wrR/jCSdQTD9f4zf5w6o7rmNQq5J+3XWFfua0rwscXEccc9gOEVE8BmTCJmbLTAO6YXO61vUm+jOUFsMhSDmh9ltQ3j+PxMpCNua8dGVIvT4YFewoPVdYhwve5xnLlFWh4yOzosZ6r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768758746; c=relaxed/simple; bh=uDUuXmqziU7AvUNIx5NUkiSffc9yPE1hPQi1KV7t5ag=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ru7HHjtgPtf0e5gQ583NL6v9SdAR2a6gDcJ+I1faEDkwoiZJ0fYM3UmIOvtlejA9vLp75SmMxCzEMHBFPTMmuILEuv+qlOVlxi8WInCAgjs8Dr2385vHA2O0W04cd074duw2oTd7GT8DjZ46Ipv4FG6i0Eq676l1J8fplIjoHek= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5C1C4BA2E2D DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=76qctGJq4lrlJdLd+7mWEiNvAwogDTdJU95IEkXW/AI=; b=uT3aoo5BDtzvaeBEDhCQbGdEUv /JJboJ9W/xRjvr3KU1dIBKnKMEChe1liPHb/F1t1BqCgql/VxchAQy5rWykxtFb18NgS/GvqyjoAB cD+/O4HshJ/swoZdu7fPgFF9+/s1QkAW9MWuak7w8KXnQcaSSRnUKQn9MLnehKKrdO3w1SqtHotZ7 mYI9rjkUrPxQj5MOaC7oXBvoqhswGlokQq0easlZO9jhW0drBwe5bHIr8MnL0dqnCs866kJ5MgOlQ SBnWxXw30qykRlixOmTfCwcFv8cOndetA/IRl86iyrr6adIpLXsl4kdJC0DQ21X2v9cjAaWyQa380 7ob2aliw==; Received: from [2a01:e34:ec5d:a741:1ee1:92ff:feb4:5ec0] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vhWwq-00000009Vg9-3i25; Sun, 18 Jan 2026 18:52:24 +0100 From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH] Fix ldbl-128ibm ceill, floorl, roundl and truncl zero-sign handling Date: Sun, 18 Jan 2026 18:47:49 +0100 Message-ID: <20260118175214.495942-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org When the result of ceill, floorl, roundl and truncl is zero, the sign of the result must match the sign of the input. For the IBM 128-bit long double format, the sign is determined by the high part. Ensure the correct sign when the high part is the result of computations, by copying the sign from the input high part to the output high part. On POWER, this conveniently maps to the fcpsgn instruction. Fixes: BZ #33623 --- sysdeps/ieee754/ldbl-128ibm/s_ceill.c | 5 +++++ sysdeps/ieee754/ldbl-128ibm/s_floorl.c | 5 +++++ sysdeps/ieee754/ldbl-128ibm/s_roundl.c | 5 +++++ sysdeps/ieee754/ldbl-128ibm/s_truncl.c | 5 +++++ 4 files changed, 20 insertions(+) For ceill, floorl and truncl, this got broken as part of the refactoring in the following commits: - commit e2310a27bede ("Fix ldbl-128ibm truncl for non-default rounding modes (bug 19593).") - commit 8a9fa0086dfe ("Fix ldbl-128ibm ceill for non-default rounding modes (bug 19592).") - commit 1833769e1923 ("Fix ldbl-128ibm floorl for non-default rounding modes (bug 17899).") Previously, the code used a comparison against zero to determine whether the input was negative, in which case the result was produced as -__builtin_fabs (xh). For roundl, it seems it has always been broken. This fixes the following tests added in 2.43 on PowerPC64LE: - FAIL: math/test-ldouble-fromfp - FAIL: math/test-ldouble-fromfpx - FAIL: math/test-ldouble-ufromfp - FAIL: math/test-ldouble-ufromfpx Tested on PowerPC64LE, no regression. diff --git a/sysdeps/ieee754/ldbl-128ibm/s_ceill.c b/sysdeps/ieee754/ldbl-128ibm/s_ceill.c index 8038cf9fda..066e66078d 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_ceill.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_ceill.c @@ -49,11 +49,16 @@ __ceill (long double x) } else { + double orig_xh = xh; + /* The high part is a nonzero integer. */ lo = ceil (xl); xh = hi; xl = lo; ldbl_canonicalize_int (&xh, &xl); + + /* Ensure we return -0 rather than +0 when appropriate. */ + xh = __builtin_copysign (xh, orig_xh); } } else diff --git a/sysdeps/ieee754/ldbl-128ibm/s_floorl.c b/sysdeps/ieee754/ldbl-128ibm/s_floorl.c index 23f45b773f..3beb806a59 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_floorl.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_floorl.c @@ -49,11 +49,16 @@ __floorl (long double x) } else { + double orig_xh = xh; + /* The high part is a nonzero integer. */ lo = floor (xl); xh = hi; xl = lo; ldbl_canonicalize_int (&xh, &xl); + + /* Ensure we return -0 rather than +0 when appropriate. */ + xh = __builtin_copysign (xh, orig_xh); } } else diff --git a/sysdeps/ieee754/ldbl-128ibm/s_roundl.c b/sysdeps/ieee754/ldbl-128ibm/s_roundl.c index e8948a0c05..1d43d4782c 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_roundl.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_roundl.c @@ -42,6 +42,8 @@ __roundl (long double x) && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { + double orig_xh = xh; + hi = round (xh); if (hi != xh) { @@ -80,6 +82,9 @@ __roundl (long double x) xh = hi; ldbl_canonicalize_int (&xh, &xl); } + + /* Ensure we return -0 rather than +0 when appropriate. */ + xh = __builtin_copysign(xh, orig_xh); } else /* Quiet signaling NaN arguments. */ diff --git a/sysdeps/ieee754/ldbl-128ibm/s_truncl.c b/sysdeps/ieee754/ldbl-128ibm/s_truncl.c index 7f0b77cd3f..b5de2ad854 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_truncl.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_truncl.c @@ -51,11 +51,16 @@ __truncl (long double x) } else { + double orig_xh = xh; + /* The high part is a nonzero integer. */ lo = xh > 0 ? floor (xl) : ceil (xl); xh = hi; xl = lo; ldbl_canonicalize_int (&xh, &xl); + + /* Ensure we return -0 rather than +0 when appropriate. */ + xh = __builtin_copysign (xh, orig_xh); } } else