Add exp10 macro to <tgmath.h> (bug 26108) [committed]

Message ID alpine.DEB.2.22.394.2109302041020.896631@digraph.polyomino.org.uk
State Committed
Commit 52c057e37c3e0d1451f1c1cc0465eddee6cf236d
Headers
Series Add exp10 macro to <tgmath.h> (bug 26108) [committed] |

Commit Message

Joseph Myers Sept. 30, 2021, 8:41 p.m. UTC
  glibc has had exp10 functions since long before they were
standardized; now they are standardized in TS 18661-4 and C2X, they
are also specified there to have a corresponding type-generic macro.
Add one to <tgmath.h>, so fixing bug 26108.

glibc doesn't have other functions from TS 18661-4 yet, but when
added, it will be natural to add the type-generic macro for each
function family at the same time as the functions.

Tested for x86_64.

---

Committed.
  

Patch

diff --git a/NEWS b/NEWS
index 6bc98873ab..a923bd644d 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,9 @@  Major new features:
 * The __STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__ macros are
   predefined as specified in TS 18661-1:2014.
 
+* The exp10 functions in <math.h> now have a corresponding type-generic
+  macro in <tgmath.h>.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The r_version update in the debugger interface makes the glibc binary
diff --git a/math/Makefile b/math/Makefile
index af734d41c4..e19f4ec343 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -374,9 +374,9 @@  $(foreach t,$(libm-tests-base),\
 tgmath3-narrow-types = f d f16 f32 f64 f128 f32x f64x
 tgmath3-narrow-macros = $(foreach t,$(tgmath3-narrow-types), \
 				    $(foreach f,$(libm-narrow-fns),$(t)$(f)))
-tgmath3-macros = atan2 cbrt ceil copysign erf erfc exp2 expm1 fdim floor \
-		 fma fmax fmin fmod frexp hypot ilogb ldexp lgamma llrint \
-		 llround log10 log1p log2 logb lrint lround nearbyint \
+tgmath3-macros = atan2 cbrt ceil copysign erf erfc exp10 exp2 expm1 fdim \
+		 floor fma fmax fmin fmod frexp hypot ilogb ldexp lgamma \
+		 llrint llround log10 log1p log2 logb lrint lround nearbyint \
 		 nextafter nexttoward remainder remquo rint round scalbn \
 		 scalbln tgamma trunc acos asin atan acosh asinh atanh cos \
 		 sin tan cosh sinh tanh exp log pow sqrt fabs carg cimag conj \
diff --git a/math/gen-tgmath-tests.py b/math/gen-tgmath-tests.py
index d433b484b8..53d5a54767 100755
--- a/math/gen-tgmath-tests.py
+++ b/math/gen-tgmath-tests.py
@@ -707,6 +707,8 @@  class Tests(object):
                                 ('_Float32x', 'f32x'),
                                 ('_Float64x', 'f64x')):
                 self.add_tests(prefix + fn, ret, ['r'] * args)
+        # TS 18661-4 functions.
+        self.add_tests('exp10', 'r', ['r'])
         # C2X functions.
         self.add_tests('fmaximum', 'r', ['r', 'r'])
         self.add_tests('fmaximum_mag', 'r', ['r', 'r'])
diff --git a/math/test-tgmath.c b/math/test-tgmath.c
index f9b5fc640f..678a174bca 100644
--- a/math/test-tgmath.c
+++ b/math/test-tgmath.c
@@ -48,7 +48,7 @@  volatile int count_cdouble;
 volatile int count_cfloat;
 volatile int count_cldouble;
 
-#define NCALLS     156
+#define NCALLS     158
 #define NCALLS_INT 4
 #define NCCALLS    47
 
@@ -253,6 +253,7 @@  F(compile_test) (void)
   a = log1p (log1p (x));
   b = logb (logb (a));
   a = exp2 (exp2 (x));
+  a = exp10 (exp10 (x));
   b = log2 (log2 (a));
   a = pow (pow (x, a), pow (c, b));
   b = sqrt (sqrt (a));
@@ -365,6 +366,7 @@  F(compile_test) (void)
       a = log1p (y);
       a = logb (y);
       a = exp2 (y);
+      a = exp10 (y);
       a = log2 (y);
       a = pow (y, y);
       a = sqrt (y);
@@ -615,6 +617,14 @@  TYPE
   return x;
 }
 
+TYPE
+(F(exp10)) (TYPE x)
+{
+  ++count;
+  P ();
+  return x;
+}
+
 TYPE
 (F(exp2)) (TYPE x)
 {
diff --git a/math/tgmath.h b/math/tgmath.h
index e8042833dd..13c7022275 100644
--- a/math/tgmath.h
+++ b/math/tgmath.h
@@ -785,6 +785,11 @@ 
 /* Compute base-2 logarithm of X.  */
 #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
 
+#if __GLIBC_USE (IEC_60559_FUNCS_EXT_C2X)
+/* Compute exponent to base ten.  */
+#define exp10(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp10)
+#endif
+
 
 /* Power functions.  */