about summary refs log tree commit diff
path: root/math
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2021-09-28 23:31:35 +0000
committerJoseph Myers <joseph@codesourcery.com>2021-09-28 23:31:35 +0000
commit90f0ac10a74b2d43b5a65aab4be40565e359be43 (patch)
treeab0e73d7c60a7255fa5e7c9cbe58e80c3eb8d9cd /math
parent5bf07e1b3a74232bfb8332275110be1a5da50f83 (diff)
downloadglibc-90f0ac10a74b2d43b5a65aab4be40565e359be43.tar.gz
glibc-90f0ac10a74b2d43b5a65aab4be40565e359be43.tar.xz
glibc-90f0ac10a74b2d43b5a65aab4be40565e359be43.zip
Add fmaximum, fminimum functions
C2X adds new <math.h> functions for floating-point maximum and
minimum, corresponding to the new operations that were added in IEEE
754-2019 because of concerns about the old operations not being
associative in the presence of signaling NaNs.  fmaximum and fminimum
handle NaNs like most <math.h> functions (any NaN argument means the
result is a quiet NaN).  fmaximum_num and fminimum_num handle both
quiet and signaling NaNs the way fmax and fmin handle quiet NaNs (if
one argument is a number and the other is a NaN, return the number),
but still raise "invalid" for a signaling NaN argument, making them
exceptions to the normal rule that a function with a floating-point
result raising "invalid" also returns a quiet NaN.  fmaximum_mag,
fminimum_mag, fmaximum_mag_num and fminimum_mag_num are corresponding
functions returning the argument with greatest or least absolute
value.  All these functions also treat +0 as greater than -0.  There
are also corresponding <tgmath.h> type-generic macros.

Add these functions to glibc.  The implementations use type-generic
templates based on those for fmax, fmin, fmaxmag and fminmag, and test
inputs are based on those for those functions with appropriate
adjustments to the expected results.  The RISC-V maintainers might
wish to add optimized versions of fmaximum_num and fminimum_num (for
float and double), since RISC-V (F extension version 2.2 and later)
provides instructions corresponding to those functions - though it
might be at least as useful to add architecture-independent built-in
functions to GCC and teach the RISC-V back end to expand those
functions inline, which is what you generally want for functions that
can be implemented with a single instruction.

Tested for x86_64 and x86, and with build-many-glibcs.py.
Diffstat (limited to 'math')
-rw-r--r--math/Makefile25
-rw-r--r--math/Versions22
-rw-r--r--math/bits/mathcalls.h26
-rwxr-xr-xmath/gen-tgmath-tests.py9
-rw-r--r--math/libm-test-fmaximum.inc130
-rw-r--r--math/libm-test-fmaximum_mag.inc144
-rw-r--r--math/libm-test-fmaximum_mag_num.inc144
-rw-r--r--math/libm-test-fmaximum_num.inc130
-rw-r--r--math/libm-test-fminimum.inc129
-rw-r--r--math/libm-test-fminimum_mag.inc143
-rw-r--r--math/libm-test-fminimum_mag_num.inc143
-rw-r--r--math/libm-test-fminimum_num.inc129
-rw-r--r--math/s_fmaximum_mag_num_template.c35
-rw-r--r--math/s_fmaximum_mag_template.c35
-rw-r--r--math/s_fmaximum_num_template.c33
-rw-r--r--math/s_fmaximum_template.c33
-rw-r--r--math/s_fminimum_mag_num_template.c35
-rw-r--r--math/s_fminimum_mag_template.c35
-rw-r--r--math/s_fminimum_num_template.c33
-rw-r--r--math/s_fminimum_template.c33
-rw-r--r--math/test-tgmath.c82
-rw-r--r--math/tgmath.h32
22 files changed, 1554 insertions, 6 deletions
diff --git a/math/Makefile b/math/Makefile
index 8d67bfff7e..af734d41c4 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -60,7 +60,10 @@ gen-libm-calls = cargF conjF cimagF crealF cabsF e_scalbF s_cacosF	  \
 		 w_exp2F w_fmodF w_hypotF w_j0F w_j1F w_jnF w_logF	  \
 		 w_log10F w_log2F w_powF w_remainderF w_scalbF		  \
 		 w_sinhF w_sqrtF					  \
-		 w_tgammaF w_lgammaF w_lgammaF_r w_expF e_exp2F
+		 w_tgammaF w_lgammaF w_lgammaF_r w_expF e_exp2F		  \
+		 s_fmaximumF s_fmaximum_magF s_fmaximum_numF		  \
+		 s_fmaximum_mag_numF s_fminimumF s_fminimum_magF	  \
+		 s_fminimum_numF s_fminimum_mag_numF
 
 libm-calls =								  \
 	e_acosF e_acoshF e_asinF e_atan2F e_atanhF e_coshF e_expF e_fmodF \
@@ -287,9 +290,11 @@ libm-test-funcs-auto = acos acosh asin asinh atan atan2 atanh cabs cacos \
 		       lgamma log log10 log1p log2 pow sin sincos sinh sqrt \
 		       tan tanh tgamma y0 y1 yn
 libm-test-funcs-noauto = canonicalize ceil cimag conj copysign cproj creal \
-			 fabs fdim floor fmax fmaxmag fmin fminmag fmod \
-			 fpclassify frexp fromfp fromfpx getpayload ilogb \
-			 iscanonical iseqsig isfinite isgreater \
+			 fabs fdim floor fmax fmaximum fmaximum_mag \
+			 fmaximum_mag_num fmaximum_num fmaxmag fmin fminimum \
+			 fminimum_mag fminimum_mag_num fminimum_num fminmag \
+			 fmod fpclassify frexp fromfp fromfpx getpayload \
+			 ilogb iscanonical iseqsig isfinite isgreater \
 			 isgreaterequal isinf isless islessequal \
 			 islessgreater isnan isnormal issignaling issubnormal \
 			 isunordered iszero llogb llrint llround logb lrint \
@@ -375,7 +380,9 @@ tgmath3-macros = atan2 cbrt ceil copysign erf erfc exp2 expm1 fdim floor \
 		 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 \
-		 cproj creal roundeven nextup nextdown fminmag fmaxmag llogb \
+		 cproj creal roundeven nextup nextdown fminmag fmaxmag \
+		 fmaximum fmaximum_mag fmaximum_num fmaximum_mag_num \
+		 fminimum fminimum_mag fminimum_num fminimum_mag_num llogb \
 		 fromfp fromfpx ufromfp ufromfpx scalb $(tgmath3-narrow-macros)
 tgmath3-macro-tests = $(addprefix test-tgmath3-,$(tgmath3-macros))
 tests += $(tgmath3-macro-tests)
@@ -682,8 +689,16 @@ CFLAGS-s_finite.c += -fno-builtin-finitel
 CFLAGS-s_floor.c += -fno-builtin-floorl
 CFLAGS-s_fma.c += -fno-builtin-fmal
 CFLAGS-s_fmax.c += -fno-builtin-fmaxl
+CFLAGS-s_fmaximum.c += -fno-builtin-fmaximuml
+CFLAGS-s_fmaximum_mag.c += -fno-builtin-fmaximum_magl
+CFLAGS-s_fmaximum_mag_num.c += -fno-builtin-fmaximum_mag_numl
+CFLAGS-s_fmaximum_num.c += -fno-builtin-fmaximum_numl
 CFLAGS-s_fmaxmag.c += -fno-builtin-fmaxmagl
 CFLAGS-s_fmin.c += -fno-builtin-fminl
+CFLAGS-s_fminimum.c += -fno-builtin-fminimuml
+CFLAGS-s_fminimum_mag.c += -fno-builtin-fminimum_magl
+CFLAGS-s_fminimum_mag_num.c += -fno-builtin-fminimum_mag_numl
+CFLAGS-s_fminimum_num.c += -fno-builtin-fminimum_numl
 CFLAGS-s_fminmag.c += -fno-builtin-fminmagl
 CFLAGS-w_fmod.c += -fno-builtin-fmodl
 CFLAGS-s_fmul.c += -fno-builtin-fmull
diff --git a/math/Versions b/math/Versions
index 1a25b2ce9a..a4b5405ddc 100644
--- a/math/Versions
+++ b/math/Versions
@@ -599,6 +599,20 @@ libm {
     f32fmaf32x; f32fmaf64; f32xfmaf64;
     fsqrt; fsqrtl; dsqrtl;
     f32sqrtf32x; f32sqrtf64; f32xsqrtf64;
+    fmaximum; fmaximumf; fmaximuml; fmaximumf32; fmaximumf64; fmaximumf32x;
+    fmaximum_num; fmaximum_numf; fmaximum_numl;
+    fmaximum_numf32; fmaximum_numf64; fmaximum_numf32x;
+    fmaximum_mag; fmaximum_magf; fmaximum_magl;
+    fmaximum_magf32; fmaximum_magf64; fmaximum_magf32x;
+    fmaximum_mag_num; fmaximum_mag_numf; fmaximum_mag_numl;
+    fmaximum_mag_numf32; fmaximum_mag_numf64; fmaximum_mag_numf32x;
+    fminimum; fminimumf; fminimuml; fminimumf32; fminimumf64; fminimumf32x;
+    fminimum_num; fminimum_numf; fminimum_numl;
+    fminimum_numf32; fminimum_numf64; fminimum_numf32x;
+    fminimum_mag; fminimum_magf; fminimum_magl;
+    fminimum_magf32; fminimum_magf64; fminimum_magf32x;
+    fminimum_mag_num; fminimum_mag_numf; fminimum_mag_numl;
+    fminimum_mag_numf32; fminimum_mag_numf64; fminimum_mag_numf32x;
     # Functions involving _Float64x or _Float128, for some configurations.
     f32fmaf64x; f32fmaf128;
     f32xfmaf64x; f32xfmaf128; f64fmaf64x; f64fmaf128;
@@ -606,5 +620,13 @@ libm {
     f32sqrtf64x; f32sqrtf128;
     f32xsqrtf64x; f32xsqrtf128; f64sqrtf64x; f64sqrtf128;
     f64xsqrtf128;
+    fmaximumf64x; fmaximumf128;
+    fmaximum_numf64x; fmaximum_numf128;
+    fmaximum_magf64x; fmaximum_magf128;
+    fmaximum_mag_numf64x; fmaximum_mag_numf128;
+    fminimumf64x; fminimumf128;
+    fminimum_numf64x; fminimum_numf128;
+    fminimum_magf64x; fminimum_magf128;
+    fminimum_mag_numf64x; fminimum_mag_numf128;
   }
 }
diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h
index dc145b4bcf..ee0c6d7219 100644
--- a/math/bits/mathcalls.h
+++ b/math/bits/mathcalls.h
@@ -378,6 +378,32 @@ __MATHCALLX (fmaxmag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
 __MATHCALLX (fminmag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
 #endif
 
+#if __GLIBC_USE (ISOC2X)
+/* Return maximum value from X and Y.  */
+__MATHCALLX (fmaximum,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return minimum value from X and Y.  */
+__MATHCALLX (fminimum,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return maximum numeric value from X and Y.  */
+__MATHCALLX (fmaximum_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return minimum numeric value from X and Y.  */
+__MATHCALLX (fminimum_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return value with maximum magnitude.  */
+__MATHCALLX (fmaximum_mag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return value with minimum magnitude.  */
+__MATHCALLX (fminimum_mag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return numeric value with maximum magnitude.  */
+__MATHCALLX (fmaximum_mag_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+
+/* Return numeric value with minimum magnitude.  */
+__MATHCALLX (fminimum_mag_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+#endif
+
 #if __GLIBC_USE (IEC_60559_EXT) || __MATH_DECLARING_FLOATN
 /* Total order operation.  */
 __MATHDECL_1 (int, totalorder,, (const _Mdouble_ *__x,
diff --git a/math/gen-tgmath-tests.py b/math/gen-tgmath-tests.py
index 6d32a4b6e4..d433b484b8 100755
--- a/math/gen-tgmath-tests.py
+++ b/math/gen-tgmath-tests.py
@@ -707,6 +707,15 @@ class Tests(object):
                                 ('_Float32x', 'f32x'),
                                 ('_Float64x', 'f64x')):
                 self.add_tests(prefix + fn, ret, ['r'] * args)
+        # C2X functions.
+        self.add_tests('fmaximum', 'r', ['r', 'r'])
+        self.add_tests('fmaximum_mag', 'r', ['r', 'r'])
+        self.add_tests('fmaximum_num', 'r', ['r', 'r'])
+        self.add_tests('fmaximum_mag_num', 'r', ['r', 'r'])
+        self.add_tests('fminimum', 'r', ['r', 'r'])
+        self.add_tests('fminimum_mag', 'r', ['r', 'r'])
+        self.add_tests('fminimum_num', 'r', ['r', 'r'])
+        self.add_tests('fminimum_mag_num', 'r', ['r', 'r'])
         # Miscellaneous functions.
         self.add_tests('scalb', 's', ['s', 's'])
 
diff --git a/math/libm-test-fmaximum.inc b/math/libm-test-fmaximum.inc
new file mode 100644
index 0000000000..72e12c4dfa
--- /dev/null
+++ b/math/libm-test-fmaximum.inc
@@ -0,0 +1,130 @@
+/* Test fmaximum.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fmaximum_test_data[] =
+  {
+    TEST_ff_f (fmaximum, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, min_subnorm_value, -min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, min_value, -min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, max_value, -max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 9, 0, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, -9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -9, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum, minus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 9, minus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -9, minus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_zero, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_zero, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, 0, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, 0, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, minus_zero, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, minus_zero, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, 9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, 9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, plus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, minus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, plus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, plus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, minus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, minus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fmaximum_test (void)
+{
+  ALL_RM_TEST (fmaximum, 1, fmaximum_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fmaximum_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fmaximum_mag.inc b/math/libm-test-fmaximum_mag.inc
new file mode 100644
index 0000000000..556188fada
--- /dev/null
+++ b/math/libm-test-fmaximum_mag.inc
@@ -0,0 +1,144 @@
+/* Test fmaximum_mag.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fmaximum_mag_test_data[] =
+  {
+    TEST_ff_f (fmaximum_mag, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_subnorm_value, -min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_value, -min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, max_value, -max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, max_value, min_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, max_value, -min_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -max_value, min_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -max_value, -min_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, min_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -min_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 9, 0, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -9, 0, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -9, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag, minus_infty, 9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_infty, -9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_zero, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_zero, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, 0, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, 0, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, minus_zero, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, minus_zero, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, 9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, 9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, plus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, minus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, plus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, plus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, minus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, minus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fmaximum_mag_test (void)
+{
+  ALL_RM_TEST (fmaximum_mag, 1, fmaximum_mag_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fmaximum_mag_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fmaximum_mag_num.inc b/math/libm-test-fmaximum_mag_num.inc
new file mode 100644
index 0000000000..75cc46484a
--- /dev/null
+++ b/math/libm-test-fmaximum_mag_num.inc
@@ -0,0 +1,144 @@
+/* Test fmaximum_mag_num.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fmaximum_mag_num_test_data[] =
+  {
+    TEST_ff_f (fmaximum_mag_num, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_subnorm_value, -min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_value, -min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, max_value, -max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, max_value, min_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, max_value, -min_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -max_value, min_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -max_value, -min_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, min_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -min_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 9, 0, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -9, 0, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag_num, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -9, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag_num, minus_infty, 9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_infty, -9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_mag_num, 0, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, -qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 9, qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 9, -qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -9, qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -9, -qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, 0, snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, 0, -snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, minus_zero, -snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, 9, snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, 9, -snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -9, snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -9, -snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, plus_infty, qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, plus_infty, -qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_infty, qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, minus_infty, -qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, plus_infty, snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, plus_infty, -snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, minus_infty, snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, minus_infty, -snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_mag_num, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fmaximum_mag_num_test (void)
+{
+  ALL_RM_TEST (fmaximum_mag_num, 1, fmaximum_mag_num_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fmaximum_mag_num_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fmaximum_num.inc b/math/libm-test-fmaximum_num.inc
new file mode 100644
index 0000000000..948be9ada2
--- /dev/null
+++ b/math/libm-test-fmaximum_num.inc
@@ -0,0 +1,130 @@
+/* Test fmaximum_num.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fmaximum_num_test_data[] =
+  {
+    TEST_ff_f (fmaximum_num, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, min_subnorm_value, -min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, min_value, -min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, max_value, -max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 9, 0, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, -9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_num, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -9, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_num, minus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 9, minus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -9, minus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fmaximum_num, 0, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_zero, qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_zero, -qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 9, qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 9, -qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -9, qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -9, -qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, 0, snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, 0, -snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, minus_zero, snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, minus_zero, -snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, 9, snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, 9, -snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -9, snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -9, -snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, plus_infty, qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, plus_infty, -qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_infty, qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, minus_infty, -qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, plus_infty, snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, plus_infty, -snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, minus_infty, snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, minus_infty, -snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaximum_num, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fmaximum_num, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fmaximum_num_test (void)
+{
+  ALL_RM_TEST (fmaximum_num, 1, fmaximum_num_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fmaximum_num_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fminimum.inc b/math/libm-test-fminimum.inc
new file mode 100644
index 0000000000..ff37fb115e
--- /dev/null
+++ b/math/libm-test-fminimum.inc
@@ -0,0 +1,129 @@
+/* Test fminimum.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fminimum_test_data[] =
+  {
+    TEST_ff_f (fminimum, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 0, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_zero, 0, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -min_subnorm_value, min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -min_value, min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -max_value, max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 0, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -9, 0, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 0, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum, plus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 9, plus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, plus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -9, plus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_infty, 9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_infty, -9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 0, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_zero, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_zero, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, 0, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, 0, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, minus_zero, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, minus_zero, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, 9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, 9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, plus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, minus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, plus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, plus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, minus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, minus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fminimum_test (void)
+{
+  ALL_RM_TEST (fminimum, 1, fminimum_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fminimum_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fminimum_mag.inc b/math/libm-test-fminimum_mag.inc
new file mode 100644
index 0000000000..b3e85b38ef
--- /dev/null
+++ b/math/libm-test-fminimum_mag.inc
@@ -0,0 +1,143 @@
+/* Test fminimum_mag.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fminimum_mag_test_data[] =
+  {
+    TEST_ff_f (fminimum_mag, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 0, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_zero, 0, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_subnorm_value, min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_value, min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -max_value, max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, max_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, max_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -max_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -max_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_value, max_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, min_value, -max_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_value, max_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -min_value, -max_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 0, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 0, -9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_mag, plus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 9, plus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, plus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -9, plus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 9, minus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -9, minus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_mag, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 0, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_zero, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_zero, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -9, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, 0, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, 0, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, minus_zero, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, minus_zero, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, 9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, 9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -9, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -9, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, plus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, minus_infty, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, plus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, plus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, minus_infty, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, minus_infty, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fminimum_mag_test (void)
+{
+  ALL_RM_TEST (fminimum_mag, 1, fminimum_mag_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fminimum_mag_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fminimum_mag_num.inc b/math/libm-test-fminimum_mag_num.inc
new file mode 100644
index 0000000000..f9e824c4cd
--- /dev/null
+++ b/math/libm-test-fminimum_mag_num.inc
@@ -0,0 +1,143 @@
+/* Test fminimum_mag_num.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fminimum_mag_num_test_data[] =
+  {
+    TEST_ff_f (fminimum_mag_num, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 0, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_zero, 0, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_subnorm_value, min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_value, min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, max_value, max_value, max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -max_value, max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, max_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, max_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -max_value, min_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -max_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_value, max_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, min_value, -max_value, min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_value, max_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -min_value, -max_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 0, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 0, -9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_mag_num, plus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 9, plus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, plus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -9, plus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 9, minus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -9, minus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_mag_num, 0, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 0, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_zero, qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_zero, -qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 9, qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 9, -qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -9, qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -9, -qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, 0, snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, 0, -snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, minus_zero, snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, minus_zero, -snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, 9, snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, 9, -snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -9, snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -9, -snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, plus_infty, qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, plus_infty, -qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_infty, qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, minus_infty, -qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, plus_infty, snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, plus_infty, -snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, minus_infty, snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, minus_infty, -snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_mag_num, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_mag_num, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fminimum_mag_num_test (void)
+{
+  ALL_RM_TEST (fminimum_mag_num, 1, fminimum_mag_num_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fminimum_mag_num_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/libm-test-fminimum_num.inc b/math/libm-test-fminimum_num.inc
new file mode 100644
index 0000000000..74c4df234c
--- /dev/null
+++ b/math/libm-test-fminimum_num.inc
@@ -0,0 +1,129 @@
+/* Test fminimum_num.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "libm-test-driver.c"
+
+static const struct test_ff_f_data fminimum_num_test_data[] =
+  {
+    TEST_ff_f (fminimum_num, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 0, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_zero, 0, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -min_subnorm_value, min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, min_value, -min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -min_value, min_value, -min_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, max_value, -max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -max_value, max_value, -max_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 0, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -9, 0, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 0, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_num, plus_infty, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 9, plus_infty, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, plus_infty, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -9, plus_infty, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_infty, 9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_infty, -9, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -9, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+
+    TEST_ff_f (fminimum_num, 0, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 0, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_zero, qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_zero, -qnan_value, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 9, qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 9, -qnan_value, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -9, qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -9, -qnan_value, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, 0, snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, 0, -snan_value, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, minus_zero, snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, minus_zero, -snan_value, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, 9, snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, 9, -snan_value, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -9, snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -9, -snan_value, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, 9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, -9, -9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, 0, 0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, 9, 9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, -9, -9, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, plus_infty, qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, plus_infty, -qnan_value, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_infty, qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, minus_infty, -qnan_value, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, plus_infty, snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, plus_infty, -snan_value, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, minus_infty, snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, minus_infty, -snan_value, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, plus_infty, plus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, minus_infty, minus_infty, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminimum_num, qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -qnan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -qnan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_ff_f (fminimum_num, -snan_value, -snan_value, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+  };
+
+static void
+fminimum_num_test (void)
+{
+  ALL_RM_TEST (fminimum_num, 1, fminimum_num_test_data, RUN_TEST_LOOP_ff_f, END);
+}
+
+static void
+do_test (void)
+{
+  fminimum_num_test ();
+}
+
+/*
+ * Local Variables:
+ * mode:c
+ * End:
+ */
diff --git a/math/s_fmaximum_mag_num_template.c b/math/s_fmaximum_mag_num_template.c
new file mode 100644
index 0000000000..5c9cef21fd
--- /dev/null
+++ b/math/s_fmaximum_mag_num_template.c
@@ -0,0 +1,35 @@
+/* Return number with maximum magnitude.
+   Copyright (C) 2016-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fmaximum_mag_num) (FLOAT x, FLOAT y)
+{
+  FLOAT ax = M_FABS (x);
+  FLOAT ay = M_FABS (y);
+  if (isgreater (ax, ay))
+    return x;
+  else if (isless (ax, ay))
+    return y;
+  else if (ax == ay)
+    return (M_COPYSIGN (1, x) >= M_COPYSIGN (1, y) ? x : y);
+  else
+    return isnan (y) ? (isnan (x) ? x + y : x) : y;
+}
+declare_mgen_alias (__fmaximum_mag_num, fmaximum_mag_num);
diff --git a/math/s_fmaximum_mag_template.c b/math/s_fmaximum_mag_template.c
new file mode 100644
index 0000000000..7e9a020344
--- /dev/null
+++ b/math/s_fmaximum_mag_template.c
@@ -0,0 +1,35 @@
+/* Return value with maximum magnitude.
+   Copyright (C) 2016-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fmaximum_mag) (FLOAT x, FLOAT y)
+{
+  FLOAT ax = M_FABS (x);
+  FLOAT ay = M_FABS (y);
+  if (isgreater (ax, ay))
+    return x;
+  else if (isless (ax, ay))
+    return y;
+  else if (ax == ay)
+    return (M_COPYSIGN (1, x) >= M_COPYSIGN (1, y) ? x : y);
+  else
+    return x + y;
+}
+declare_mgen_alias (__fmaximum_mag, fmaximum_mag);
diff --git a/math/s_fmaximum_num_template.c b/math/s_fmaximum_num_template.c
new file mode 100644
index 0000000000..ce0042fd5c
--- /dev/null
+++ b/math/s_fmaximum_num_template.c
@@ -0,0 +1,33 @@
+/* Return maximum number of X and Y.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fmaximum_num) (FLOAT x, FLOAT y)
+{
+  if (isgreater (x, y))
+    return x;
+  else if (isless (x, y))
+    return y;
+  else if (x == y)
+    return (M_COPYSIGN (1, x) >= M_COPYSIGN (1, y) ? x : y);
+  else
+    return isnan (y) ? (isnan (x) ? x + y : x) : y;
+}
+declare_mgen_alias (__fmaximum_num, fmaximum_num);
diff --git a/math/s_fmaximum_template.c b/math/s_fmaximum_template.c
new file mode 100644
index 0000000000..e49c5d3c0f
--- /dev/null
+++ b/math/s_fmaximum_template.c
@@ -0,0 +1,33 @@
+/* Return maximum of X and Y.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fmaximum) (FLOAT x, FLOAT y)
+{
+  if (isgreater (x, y))
+    return x;
+  else if (isless (x, y))
+    return y;
+  else if (x == y)
+    return (M_COPYSIGN (1, x) >= M_COPYSIGN (1, y) ? x : y);
+  else
+    return x + y;
+}
+declare_mgen_alias (__fmaximum, fmaximum);
diff --git a/math/s_fminimum_mag_num_template.c b/math/s_fminimum_mag_num_template.c
new file mode 100644
index 0000000000..f2dc3821ba
--- /dev/null
+++ b/math/s_fminimum_mag_num_template.c
@@ -0,0 +1,35 @@
+/* Return number with minimum magnitude.
+   Copyright (C) 2016-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fminimum_mag_num) (FLOAT x, FLOAT y)
+{
+  FLOAT ax = M_FABS (x);
+  FLOAT ay = M_FABS (y);
+  if (isless (ax, ay))
+    return x;
+  else if (isgreater (ax, ay))
+    return y;
+  else if (ax == ay)
+    return (M_COPYSIGN (1, x) <= M_COPYSIGN (1, y) ? x : y);
+  else
+    return isnan (y) ? (isnan (x) ? x + y : x) : y;
+}
+declare_mgen_alias (__fminimum_mag_num, fminimum_mag_num);
diff --git a/math/s_fminimum_mag_template.c b/math/s_fminimum_mag_template.c
new file mode 100644
index 0000000000..4a35596ba1
--- /dev/null
+++ b/math/s_fminimum_mag_template.c
@@ -0,0 +1,35 @@
+/* Return value with minimum magnitude.
+   Copyright (C) 2016-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fminimum_mag) (FLOAT x, FLOAT y)
+{
+  FLOAT ax = M_FABS (x);
+  FLOAT ay = M_FABS (y);
+  if (isless (ax, ay))
+    return x;
+  else if (isgreater (ax, ay))
+    return y;
+  else if (ax == ay)
+    return (M_COPYSIGN (1, x) <= M_COPYSIGN (1, y) ? x : y);
+  else
+    return x + y;
+}
+declare_mgen_alias (__fminimum_mag, fminimum_mag);
diff --git a/math/s_fminimum_num_template.c b/math/s_fminimum_num_template.c
new file mode 100644
index 0000000000..cdc245da32
--- /dev/null
+++ b/math/s_fminimum_num_template.c
@@ -0,0 +1,33 @@
+/* Return minimum number of X and Y.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fminimum_num) (FLOAT x, FLOAT y)
+{
+  if (isless (x, y))
+    return x;
+  else if (isgreater (x, y))
+    return y;
+  else if (x == y)
+    return (M_COPYSIGN (1, x) <= M_COPYSIGN (1, y) ? x : y);
+  else
+    return isnan (y) ? (isnan (x) ? x + y : x) : y;
+}
+declare_mgen_alias (__fminimum_num, fminimum_num);
diff --git a/math/s_fminimum_template.c b/math/s_fminimum_template.c
new file mode 100644
index 0000000000..9da7beb674
--- /dev/null
+++ b/math/s_fminimum_template.c
@@ -0,0 +1,33 @@
+/* Return minimum of X and Y.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+FLOAT
+M_DECL_FUNC (__fminimum) (FLOAT x, FLOAT y)
+{
+  if (isless (x, y))
+    return x;
+  else if (isgreater (x, y))
+    return y;
+  else if (x == y)
+    return (M_COPYSIGN (1, x) <= M_COPYSIGN (1, y) ? x : y);
+  else
+    return x + y;
+}
+declare_mgen_alias (__fminimum, fminimum);
diff --git a/math/test-tgmath.c b/math/test-tgmath.c
index 6ec7760c62..f9b5fc640f 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     132
+#define NCALLS     156
 #define NCALLS_INT 4
 #define NCCALLS    47
 
@@ -290,6 +290,14 @@ F(compile_test) (void)
   a = fmin (fmin (x, a), fmin (c, b));
   b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
   a = fminmag (fminmag (x, a), fminmag (c, b));
+  b = fmaximum (fmaximum (a, x), fmaximum (c, b));
+  a = fminimum (fminimum (x, a), fminimum (c, b));
+  b = fmaximum_num (fmaximum_num (a, x), fmaximum_num (c, b));
+  a = fminimum_num (fminimum_num (x, a), fminimum_num (c, b));
+  b = fmaximum_mag (fmaximum_mag (a, x), fmaximum_mag (c, b));
+  a = fminimum_mag (fminimum_mag (x, a), fminimum_mag (c, b));
+  b = fmaximum_mag_num (fmaximum_mag_num (a, x), fmaximum_mag_num (c, b));
+  a = fminimum_mag_num (fminimum_mag_num (x, a), fminimum_mag_num (c, b));
   b = fma (sin (a), sin (x), sin (c));
 
 #ifdef TEST_INT
@@ -393,6 +401,14 @@ F(compile_test) (void)
       a = fmin (y, y);
       a = fmaxmag (y, y);
       a = fminmag (y, y);
+      a = fmaximum (y, y);
+      a = fminimum (y, y);
+      a = fmaximum_num (y, y);
+      a = fminimum_num (y, y);
+      a = fmaximum_mag (y, y);
+      a = fminimum_mag (y, y);
+      a = fmaximum_mag_num (y, y);
+      a = fminimum_mag_num (y, y);
       a = fma (y, y, y);
 
 #ifdef TEST_INT
@@ -944,6 +960,70 @@ TYPE
 }
 
 TYPE
+(F(fminimum)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fmaximum)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fminimum_num)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fmaximum_num)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fminimum_mag)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fmaximum_mag)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fminimum_mag_num)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
+(F(fmaximum_mag_num)) (TYPE x, TYPE y)
+{
+  ++count;
+  P ();
+  return x + y;
+}
+
+TYPE
 (F(fma)) (TYPE x, TYPE y, TYPE z)
 {
   ++count;
diff --git a/math/tgmath.h b/math/tgmath.h
index 5fdc7982b2..9868353c46 100644
--- a/math/tgmath.h
+++ b/math/tgmath.h
@@ -929,6 +929,38 @@
 # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
 #endif
 
+#if __GLIBC_USE (ISOC2X)
+/* Return maximum value from X and Y.  */
+# define fmaximum(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum)
+
+/* Return minimum value from X and Y.  */
+# define fminimum(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum)
+
+/* Return maximum numeric value from X and Y.  */
+# define fmaximum_num(Val1, Val2)			\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_num)
+
+/* Return minimum numeric value from X and Y.  */
+# define fminimum_num(Val1, Val2)			\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_num)
+
+/* Return value with maximum magnitude.  */
+# define fmaximum_mag(Val1, Val2)			\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_mag)
+
+/* Return value with minimum magnitude.  */
+# define fminimum_mag(Val1, Val2)			\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_mag)
+
+/* Return numeric value with maximum magnitude.  */
+# define fmaximum_mag_num(Val1, Val2)				\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_mag_num)
+
+/* Return numeric value with minimum magnitude.  */
+# define fminimum_mag_num(Val1, Val2)				\
+  __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_mag_num)
+#endif
+
 
 /* Absolute value, conjugates, and projection.  */