]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Order signed zeros in f{max,min}mag{f,l,f128}
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 23 Jan 2026 13:02:21 +0000 (10:02 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 2 Feb 2026 17:35:44 +0000 (14:35 -0300)
The functions are documented to behave like fmax/fmin when the
arguments have the same absolute value.

Checked on x86_64-linux-gnu, aarch64-linux-gnu, i686-linux-gnu,
arm-linux-gnueabihf, powerpc64le-linux-gnu,
riscv64-linux-gnu-rv64imafdc-lp64d, and loongarch64-linux-gnuf64.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
manual/arith.texi
math/libm-test-fmaxmag.inc
math/libm-test-fminmag.inc
math/s_fmaxmag_template.c
math/s_fminmag_template.c

index 7846b6903ecf0e10fa9985c08f01af84f2fc67cb..df6d25e0ba850ddb7fe28c4d65f1de6e4757f14d 100644 (file)
@@ -2201,7 +2201,8 @@ treated as greater than negative zero.
 These functions, from TS 18661-1:2014 and TS 18661-3:2015, 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{fmin} functions.
+behave the same as the @code{fmin} functions (including the order of
+signed zeros).
 @end deftypefun
 
 @deftypefun double fmaxmag (double @var{x}, double @var{y})
index 3940a4553697e2f55f92048f2bd8ce11281aaf83..45f38732253e424239d2e216d166ff1518b30f22 100644 (file)
@@ -22,8 +22,9 @@ static const struct test_ff_f_data fmaxmag_test_data[] =
   {
     TEST_ff_f (fmaxmag, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fmaxmag, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
-    TEST_ff_f (fmaxmag, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|IGNORE_ZERO_INF_SIGN),
-    TEST_ff_f (fmaxmag, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|IGNORE_ZERO_INF_SIGN),
+    /* The order signed zeros are implemented as a QoI in the generic implementation.  */
+    TEST_ff_f (fmaxmag, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fmaxmag, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fmaxmag, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fmaxmag, min_subnorm_value, -min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fmaxmag, -min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
index 5c80e84de3a829e4ace53e685b0f376cfcbc1b96..979b10eb97abfe3f4a7f4eccdf42c38bab61603c 100644 (file)
@@ -22,8 +22,9 @@ static const struct test_ff_f_data fminmag_test_data[] =
   {
     TEST_ff_f (fminmag, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fminmag, minus_zero, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
-    TEST_ff_f (fminmag, 0, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|IGNORE_ZERO_INF_SIGN),
-    TEST_ff_f (fminmag, minus_zero, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|IGNORE_ZERO_INF_SIGN),
+    /* The order signed zeros are implemented as a QoI in the generic implementation.  */
+    TEST_ff_f (fminmag, 0, minus_zero, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (fminmag, minus_zero, 0, minus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fminmag, min_subnorm_value, min_subnorm_value, min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fminmag, min_subnorm_value, -min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (fminmag, -min_subnorm_value, min_subnorm_value, -min_subnorm_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
index 915f1992839546b0acc14e639dd439d49513a0c8..11df91d09236bf0fe90591d7da8b5c6dba0870e9 100644 (file)
@@ -26,7 +26,7 @@ M_DECL_FUNC (__fmaxmag) (FLOAT x, FLOAT y)
       FLOAT ax = M_FABS (x);
       FLOAT ay = M_FABS (y);
       if (__glibc_unlikely (ax == ay))
-       return x > y ? x : y;
+        return signbit (x) ? y : x;
       return isgreater (ax, ay) ? x : y;
     }
   else if (issignaling (x) || issignaling (y))
index d4960baefa48f7bb2bcb01235868d68565e045a1..88fbac61e575ee8ef1e249ce699d6141fdd2829e 100644 (file)
@@ -26,7 +26,7 @@ M_DECL_FUNC (__fminmag) (FLOAT x, FLOAT y)
       FLOAT ax = M_FABS (x);
       FLOAT ay = M_FABS (y);
       if (__glibc_unlikely (ax == ay))
-       return x < y ? x : y;
+        return signbit (x) ? x : y;
       return isless (ax, ay) ? x : y;
     }
   else if (issignaling (x) || issignaling (y))