diff mbox series

[12/15] math: Fix log10 template for inputs less than 0

Message ID 20240327164527.3717523-13-adhemerval.zanella@linaro.org
State New
Headers show
Series Fix some libm static issues | expand

Commit Message

Adhemerval Zanella March 27, 2024, 4:45 p.m. UTC
The template is used by some ABIs for the static build, and it
fails to correct set the floating exceptions if the argument is
less than 0.

Checked on x86_64-linux-gnu.
---
 math/Makefile           |  1 +
 math/w_log10_template.c | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/math/Makefile b/math/Makefile
index 2b2683a9fa..aa57171f77 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -370,6 +370,7 @@  $(libm-test-c-narrow-obj): $(objpfx)libm-test%.c: libm-test%.inc \
 libm-test-funcs-auto-static = \
   acos \
   exp10 \
+  log10 \
   # libm-test-funcs-auto-static
 libm-test-funcs-noauto-static = \
   copysign \
diff --git a/math/w_log10_template.c b/math/w_log10_template.c
index aca38d4e1e..cc7b503f01 100644
--- a/math/w_log10_template.c
+++ b/math/w_log10_template.c
@@ -32,11 +32,19 @@  M_DECL_FUNC (__log10) (FLOAT x)
   if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
     {
       if (x == 0)
-	/* Pole error: log10(0).  */
-	__set_errno (ERANGE);
+	{
+	  /* Pole error: log10(0).  */
+	  __feraiseexcept (FE_DIVBYZERO);
+	  __set_errno (ERANGE);
+	  return -INFINITY;
+	}
       else
-	/* Domain error: log10(<0).  */
-	__set_errno (EDOM);
+	{
+	  /* Domain error: log10(<0).  */
+	  __feraiseexcept (FE_INVALID);
+	  __set_errno (EDOM);
+	  return NAN;
+	}
     }
   return M_SUF (__ieee754_log10) (x);
 }