From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 45A453853D7E; Wed, 23 Nov 2022 14:38:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45A453853D7E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669214310; bh=/zv/XIYBcsBqhiB8rqnIAC03NLqbcWXjIBHUWJUQ8j4=; h=From:To:Subject:Date:From; b=wWb0NDBOFB2vngLJzD5viJ+9nPsAqrQYlNwXLP5TFmx0QjSOXLt9TYreumTNmNPtP WC7A/G8rj+0Zobb2Vv4WjqRvSlTqhD05WONqZJJN9Y0ydlU7pgm929i530Cr1pSZdU 3iZ72hqIqeHfNJxKtpI+Rlu8Ttp/RA1/gh5GAnb4= 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 with old gcc X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 2ba9801d9f222de9fe1f5f04dcd1c276e56b4245 X-Git-Newrev: 5aa16bb318c542cc9a2a5b48cf90b5dd8f0873ec Message-Id: <20221123143830.45A453853D7E@sourceware.org> Date: Wed, 23 Nov 2022 14:38:30 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5aa16bb318c542cc9a2a5b48cf90b5dd8f0873ec commit 5aa16bb318c542cc9a2a5b48cf90b5dd8f0873ec Author: Szabolcs Nagy Date: Thu Oct 13 11:10:10 2022 +0100 math: Fix asin and acos invalid exception with old gcc This works around a gcc issue where it const folded inf/inf into nan, preventing the invalid exception to be signalled. (x-x)/(x-x) is more robust against optimizations and works for all out of bounds values including x==nan. The gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95115 should be fixed on release branches starting from gcc-10, but it is better to change the code in case glibc is built with older gcc. 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)