aboutsummaryrefslogtreecommitdiff
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
parent5bf07e1b3a74232bfb8332275110be1a5da50f83 (diff)
downloadglibc-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.
-rw-r--r--NEWS7
-rw-r--r--manual/arith.texi110
-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
-rw-r--r--sysdeps/ieee754/ldbl-128ibm-compat/Versions8
-rw-r--r--sysdeps/ieee754/ldbl-opt/Makefile12
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fmaximum.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fmaximum_mag.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fmaximum_mag_num.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fmaximum_num.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fminimum.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fminimum_mag.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fminimum_mag_num.c26
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-fminimum_num.c26
-rw-r--r--sysdeps/mach/hurd/i386/libm.abilist64
-rw-r--r--sysdeps/powerpc/nofpu/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/alpha/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/arc/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/arm/be/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/arm/le/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/csky/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/hppa/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/i386/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/ia64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/microblaze/be/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/microblaze/le/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/mips/mips32/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/mips/mips64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/nios2/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist72
-rw-r--r--sysdeps/unix/sysv/linux/riscv/rv32/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/riscv/rv64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/sh/be/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/sh/le/libm.abilist48
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/64/libm.abilist64
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist64
66 files changed, 3634 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index 9ae04b2f20..6bc98873ab 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,13 @@ Major new features:
- ffma, ffmal, dfmal and corresponding fMfmafN, fMfmafNx, fMxfmafN and
fMxfmafNx functions.
+* <math.h> functions for floating-point maximum and minimum,
+ corresponding to new operations in IEEE 754-2019, and corresponding
+ <tgmath.h> macros, are added from draft ISO C2X: fmaximum,
+ fmaximum_num, fmaximum_mag, fmaximum_mag_num, fminimum, fminimum_num,
+ fminimum_mag, fminimum_mag_num and corresponding functions for float,
+ long double, _FloatN and _FloatNx.
+
* The __STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__ macros are
predefined as specified in TS 18661-1:2014.
diff --git a/manual/arith.texi b/manual/arith.texi
index 6a158e624d..edb9cfdafb 100644
--- a/manual/arith.texi
+++ b/manual/arith.texi
@@ -2097,8 +2097,8 @@ and @var{y}. It is similar to the expression
@end smallexample
except that @var{x} and @var{y} are only evaluated once.
-If an argument is NaN, the other argument is returned. If both arguments
-are NaN, NaN is returned.
+If an argument is a quiet NaN, the other argument is returned. If both arguments
+are NaN, or either is a signaling NaN, NaN is returned.
@end deftypefun
@deftypefun double fmax (double @var{x}, double @var{y})
@@ -2113,8 +2113,58 @@ are NaN, NaN is returned.
The @code{fmax} function returns the greater of the two values @var{x}
and @var{y}.
-If an argument is NaN, the other argument is returned. If both arguments
-are NaN, NaN is returned.
+If an argument is a quiet NaN, the other argument is returned. If both arguments
+are NaN, or either is a signaling NaN, NaN is returned.
+@end deftypefun
+
+@deftypefun double fminimum (double @var{x}, double @var{y})
+@deftypefunx float fminimumf (float @var{x}, float @var{y})
+@deftypefunx {long double} fminimuml (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fminimumfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fminimumfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{fminimum} function returns the lesser of the two values @var{x}
+and @var{y}. Unlike @code{fmin}, if either argument is a NaN, NaN is returned.
+Positive zero is treated as greater than negative zero.
+@end deftypefun
+
+@deftypefun double fmaximum (double @var{x}, double @var{y})
+@deftypefunx float fmaximumf (float @var{x}, float @var{y})
+@deftypefunx {long double} fmaximuml (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fmaximumfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fmaximumfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{fmaximum} function returns the greater of the two values @var{x}
+and @var{y}. Unlike @code{fmax}, if either argument is a NaN, NaN is returned.
+Positive zero is treated as greater than negative zero.
+@end deftypefun
+
+@deftypefun double fminimum_num (double @var{x}, double @var{y})
+@deftypefunx float fminimum_numf (float @var{x}, float @var{y})
+@deftypefunx {long double} fminimum_numl (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fminimum_numfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fminimum_numfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{fminimum_num} function returns the lesser of the two values
+@var{x} and @var{y}. If one argument is a number and the other is a
+NaN, even a signaling NaN, the number is returned. Positive zero is
+treated as greater than negative zero.
+@end deftypefun
+
+@deftypefun double fmaximum_num (double @var{x}, double @var{y})
+@deftypefunx float fmaximum_numf (float @var{x}, float @var{y})
+@deftypefunx {long double} fmaximum_numl (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fmaximum_numfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fmaximum_numfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{fmaximum_num} function returns the greater of the two values
+@var{x} and @var{y}. If one argument is a number and the other is a
+NaN, even a signaling NaN, the number is returned. Positive zero is
+treated as greater than negative zero.
@end deftypefun
@deftypefun double fminmag (double @var{x}, double @var{y})
@@ -2147,6 +2197,58 @@ have the same absolute value, or either is NaN, they behave the same
as the @code{fmax} functions.
@end deftypefun
+@deftypefun double fminimum_mag (double @var{x}, double @var{y})
+@deftypefunx float fminimum_magf (float @var{x}, float @var{y})
+@deftypefunx {long double} fminimum_magl (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fminimum_magfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fminimum_magfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+These functions return whichever of the two values @var{x} and @var{y}
+has the smaller absolute value. If both have the same absolute value,
+or either is NaN, they behave the same as the @code{fminimum}
+functions.
+@end deftypefun
+
+@deftypefun double fmaximum_mag (double @var{x}, double @var{y})
+@deftypefunx float fmaximum_magf (float @var{x}, float @var{y})
+@deftypefunx {long double} fmaximum_magl (long double @var{x}, long double @var{y})
+@deftypefunx _FloatN fmaximum_magfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
+@deftypefunx _FloatNx fmaximum_magfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
+@standards{C2X, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+These functions return whichever of the two values @var{x} and @var{y}
+has the greater absolute value. If both have the same absolute value,
+or either is NaN, they behave the same as the @code{fmaximum}
+functions.
+@end deftypefun
+
+@deftype