From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 2DB75384D1BF; Thu, 20 Oct 2022 17:21:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DB75384D1BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666286473; bh=GE8zXW14Lmt8gPzSMg8frUdn4/2pHbOWocfvHbf8J6Y=; h=From:To:Subject:Date:From; b=HYY8cxihRRjjo5xEweKSUdyxVBxWBWDGBXUvklM6hbegxMa1wutsam13iDk5zGNyW MHIEupxFXq6XlK7bPXQE6Dy5Zw0/U1LjO+m/w05lv3bJeEIicZ1lrgGCp/eFrLpECo MxckoMCByA2+OlA9UK/ROJnGA4eg5Q/S21Yr0pW8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] math: Fix asin and acos invalid exception X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: f660eb9cc7ddaed3900d0cb3b2468816790855ff X-Git-Newrev: 4ad4ea848b335d803bcf4754a1cea78f697eaec5 Message-Id: <20221020172113.2DB75384D1BF@sourceware.org> Date: Thu, 20 Oct 2022 17:21:13 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4ad4ea848b335d803bcf4754a1cea78f697eaec5 commit 4ad4ea848b335d803bcf4754a1cea78f697eaec5 Author: Szabolcs Nagy Date: Thu Oct 13 11:10:10 2022 +0100 math: Fix asin and acos invalid exception This works around a gcc issue where it const folds inf/inf into nan, preventing the invalid exception signal to be raised. (x-x)/(x-x) is more robust against optimizations and works for x==nan too. The issue should be fixed in gcc-11.3.0 and gcc-12, but glibc supports older compilers. Diff: --- sysdeps/ieee754/dbl-64/e_asin.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/sysdeps/ieee754/dbl-64/e_asin.c b/sysdeps/ieee754/dbl-64/e_asin.c index e7ea0cbe8f..6b7c971e76 100644 --- a/sysdeps/ieee754/dbl-64/e_asin.c +++ b/sysdeps/ieee754/dbl-64/e_asin.c @@ -165,14 +165,7 @@ __ieee754_asin(double x){ /*---------------------------- |x|>=1 -------------------------------*/ else if (k==0x3ff00000 && u.i[LOW_HALF]==0) return (m>0)?hp0.x:-hp0.x; else - if (k>0x7ff00000 || (k == 0x7ff00000 && u.i[LOW_HALF] != 0)) return x + x; - else { - u.i[HIGH_HALF]=0x7ff00000; - v.i[HIGH_HALF]=0x7ff00000; - u.i[LOW_HALF]=0; - v.i[LOW_HALF]=0; - return u.x/v.x; /* NaN */ - } + return (x - x) / (x - x); } #ifndef __ieee754_asin libm_alias_finite (__ieee754_asin, __asin) @@ -334,14 +327,7 @@ __ieee754_acos(double x) else if (k==0x3ff00000 && u.i[LOW_HALF]==0) return (m>0)?0:2.0*hp0.x; else - if (k>0x7ff00000 || (k == 0x7ff00000 && u.i[LOW_HALF] != 0)) return x + x; - else { - u.i[HIGH_HALF]=0x7ff00000; - v.i[HIGH_HALF]=0x7ff00000; - u.i[LOW_HALF]=0; - v.i[LOW_HALF]=0; - return u.x/v.x; - } + return (x - x) / (x - x); } #ifndef __ieee754_acos libm_alias_finite (__ieee754_acos, __acos)