public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] math: Fix asin and acos invalid exception
@ 2022-10-20 17:21 Szabolcs Nagy
  0 siblings, 0 replies; only message in thread
From: Szabolcs Nagy @ 2022-10-20 17:21 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4ad4ea848b335d803bcf4754a1cea78f697eaec5

commit 4ad4ea848b335d803bcf4754a1cea78f697eaec5
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
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)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-20 17:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20 17:21 [glibc/arm/morello/main] math: Fix asin and acos invalid exception Szabolcs Nagy

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).