[PATCH 11/15] math: Fix acos template for arguments greater than 1

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Mar 27 16:45:23 GMT 2024


The template is used by some ABsI for static build, and it fails set
the expected floating exceptions if the argument is outside of the
range (on x86_64 this triggers an overflow calculation in
__ieee754_acos).

Checked on x86_64-linux-gnu.
---
 math/Makefile          | 1 +
 math/w_acos_template.c | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/math/Makefile b/math/Makefile
index af1909d0c7..2b2683a9fa 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -368,6 +368,7 @@ $(libm-test-c-narrow-obj): $(objpfx)libm-test%.c: libm-test%.inc \
 
 
 libm-test-funcs-auto-static = \
+  acos \
   exp10 \
   # libm-test-funcs-auto-static
 libm-test-funcs-noauto-static = \
diff --git a/math/w_acos_template.c b/math/w_acos_template.c
index fe6d6c01db..f4b0e91ae1 100644
--- a/math/w_acos_template.c
+++ b/math/w_acos_template.c
@@ -30,8 +30,13 @@ FLOAT
 M_DECL_FUNC (__acos) (FLOAT x)
 {
   if (__glibc_unlikely (isgreater (M_FABS (x), M_LIT (1.0))))
-    /* Domain error: acos(|x|>1).  */
-    __set_errno (EDOM);
+    {
+      /* Domain error: acos(|x|>1).  */
+      __feraiseexcept (FE_INVALID);
+      __set_errno (EDOM);
+      return __builtin_nanl ("");
+    }
+
   return M_SUF (__ieee754_acos) (x);
 }
 declare_mgen_alias (__acos, acos)
-- 
2.34.1



More information about the Libc-alpha mailing list