From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Szabolcs Nagy <Szabolcs.Nagy@arm.com>
Cc: 'GNU C Library' <libc-alpha@sourceware.org>
Subject: [PATCH] math: Fix asin and acos invalid exception with old gcc
Date: Fri, 14 Oct 2022 14:31:45 +0000 [thread overview]
Message-ID: <AS4PR08MB79016FB7C4F19D7160A1B67983249@AS4PR08MB7901.eurprd08.prod.outlook.com> (raw)
Hi Szabolcs,
> 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.
LGTM.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cheers,
Wilco
---
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)
next reply other threads:[~2022-10-14 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 14:31 Wilco Dijkstra [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-10-14 12:41 Szabolcs Nagy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS4PR08MB79016FB7C4F19D7160A1B67983249@AS4PR08MB7901.eurprd08.prod.outlook.com \
--to=wilco.dijkstra@arm.com \
--cc=Szabolcs.Nagy@arm.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).