aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/clang/include/llvm/Config/config.h4
-rw-r--r--lib/libc++/Makefile1
-rw-r--r--lib/libc++/module.modulemap4
-rw-r--r--lib/libc/tests/sys/Makefile1
-rw-r--r--lib/libpfctl/libpfctl.c6
-rw-r--r--lib/libpfctl/libpfctl.h2
-rw-r--r--lib/libsys/execve.213
-rw-r--r--lib/libsys/intro.25
-rw-r--r--lib/libusb/libusb.h7
-rw-r--r--lib/libusb/libusb10.c4
-rw-r--r--lib/msun/Makefile18
-rw-r--r--lib/msun/Symbol.map18
-rw-r--r--lib/msun/man/fmaximum_mag.32
-rw-r--r--lib/msun/man/fmaximum_mag_num.3109
-rw-r--r--lib/msun/man/math.38
-rw-r--r--lib/msun/src/math.h18
-rw-r--r--lib/msun/src/s_fmaximum_mag_num.c88
-rw-r--r--lib/msun/src/s_fmaximum_mag_numf.c84
-rw-r--r--lib/msun/src/s_fmaximum_mag_numl.c77
-rw-r--r--lib/msun/src/s_fmaximum_num.c14
-rw-r--r--lib/msun/src/s_fmaximum_numf.c14
-rw-r--r--lib/msun/src/s_fmaximum_numl.c14
-rw-r--r--lib/msun/src/s_fminimum_mag_num.c90
-rw-r--r--lib/msun/src/s_fminimum_mag_numf.c85
-rw-r--r--lib/msun/src/s_fminimum_mag_numl.c79
-rw-r--r--lib/msun/src/s_fminimum_num.c14
-rw-r--r--lib/msun/src/s_fminimum_numf.c14
-rw-r--r--lib/msun/src/s_fminimum_numl.c14
-rw-r--r--lib/msun/tests/fmaximum_fminimum_test.c28
29 files changed, 776 insertions, 59 deletions
diff --git a/lib/clang/include/llvm/Config/config.h b/lib/clang/include/llvm/Config/config.h
index 0aea32fa9dce..c11e78f74caf 100644
--- a/lib/clang/include/llvm/Config/config.h
+++ b/lib/clang/include/llvm/Config/config.h
@@ -114,12 +114,12 @@
#define HAVE_PTHREAD_SETNAME_NP 1
/* Define to 1 if you have the `pthread_get_name_np' function. */
-#if !defined(__linux__)
+#if defined(__FreeBSD__)
#define HAVE_PTHREAD_GET_NAME_NP 1
#endif
/* Define to 1 if you have the `pthread_set_name_np' function. */
-#if !defined(__linux__)
+#if defined(__FreeBSD__)
#define HAVE_PTHREAD_SET_NAME_NP 1
#endif
diff --git a/lib/libc++/Makefile b/lib/libc++/Makefile
index 03b04afee7cc..4e487f0e8457 100644
--- a/lib/libc++/Makefile
+++ b/lib/libc++/Makefile
@@ -232,7 +232,6 @@ STD_HEADERS+= stdatomic.h
STD_HEADERS+= stdbool.h
STD_HEADERS+= stddef.h
STD_HEADERS+= stdexcept
-STD_HEADERS+= stdint.h
STD_HEADERS+= stdio.h
STD_HEADERS+= stdlib.h
STD_HEADERS+= stop_token
diff --git a/lib/libc++/module.modulemap b/lib/libc++/module.modulemap
index 90d61bf5f44a..a6e6059ab60e 100644
--- a/lib/libc++/module.modulemap
+++ b/lib/libc++/module.modulemap
@@ -2433,10 +2433,6 @@ module std_stddef_h [system] {
// <stddef.h> supports being included multiple times with different pre-defined macros
textual header "stddef.h"
}
-module std_stdint_h [system] {
- // <stdint.h> supports being included multiple times with different pre-defined macros
- textual header "stdint.h"
-}
module std_stdio_h [system] {
// <stdio.h> supports being included multiple times with different pre-defined macros
textual header "stdio.h"
diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile
index 88f8191a16eb..ef689dcf019c 100644
--- a/lib/libc/tests/sys/Makefile
+++ b/lib/libc/tests/sys/Makefile
@@ -22,6 +22,7 @@ NETBSD_ATF_TESTS_C+= dup_test
NETBSD_ATF_TESTS_C+= fsync_test
NETBSD_ATF_TESTS_C+= getcontext_test
NETBSD_ATF_TESTS_C+= getgroups_test
+FORTIFY_SOURCE.t_getgroups.c= 0
NETBSD_ATF_TESTS_C+= getitimer_test
NETBSD_ATF_TESTS_C+= getlogin_test
NETBSD_ATF_TESTS_C+= getpid_test
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 59783592a370..4e51167b401a 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -1929,6 +1929,8 @@ static const struct snl_attr_parser nla_p_skey[] = {
SNL_DECLARE_ATTR_PARSER(skey_parser, nla_p_skey);
#undef _OUT
+SNL_DECLARE_ATTR_PARSER(rule_parser, ap_getrule);
+
#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pfctl_state, _field)
static struct snl_attr_parser ap_state[] = {
@@ -1963,6 +1965,7 @@ static struct snl_attr_parser ap_state[] = {
{ .type = PF_ST_RT_IFNAME, .off = _OUT(rt_ifname), .cb = snl_attr_store_ifname },
{ .type = PF_ST_SRC_NODE_FLAGS, .off = _OUT(src_node_flags), .cb = snl_attr_get_uint8 },
{ .type = PF_ST_RT_AF, .off = _OUT(rt_af), .cb = snl_attr_get_uint8 },
+ { .type = PF_ST_CREATED_BY_RULE, .off = _OUT(created_by_rule), .arg = &rule_parser, .cb = snl_attr_get_nested },
};
#undef _IN
#undef _OUT
@@ -1988,6 +1991,7 @@ pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pf
snl_add_msg_attr_u8(&nw, PF_ST_AF, filter->af);
snl_add_msg_attr_ip6(&nw, PF_ST_FILTER_ADDR, &filter->addr.v6);
snl_add_msg_attr_ip6(&nw, PF_ST_FILTER_MASK, &filter->mask.v6);
+ snl_add_msg_attr_bool(&nw, PF_ST_INCLUDE_RULE, filter->include_rule);
hdr = snl_finalize_msg(&nw);
if (hdr == NULL)
@@ -2009,7 +2013,7 @@ pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pf
return (ret);
}
- return (0);
+ return (e.error);
}
int
diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h
index 1012be53db65..3080209ec7a0 100644
--- a/lib/libpfctl/libpfctl.h
+++ b/lib/libpfctl/libpfctl.h
@@ -406,6 +406,7 @@ struct pfctl_state {
char rt_ifname[IFNAMSIZ];
sa_family_t rt_af;
uint8_t src_node_flags;
+ struct pfctl_rule created_by_rule;
};
TAILQ_HEAD(pfctl_statelist, pfctl_state);
@@ -504,6 +505,7 @@ struct pfctl_state_filter {
sa_family_t af;
struct pf_addr addr;
struct pf_addr mask;
+ bool include_rule;
};
typedef int (*pfctl_get_state_fn)(struct pfctl_state *, void *);
int pfctl_get_states_iter(pfctl_get_state_fn f, void *arg);
diff --git a/lib/libsys/execve.2 b/lib/libsys/execve.2
index dc85b9321e48..5562e198239a 100644
--- a/lib/libsys/execve.2
+++ b/lib/libsys/execve.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 02, 2025
+.Dd April 29, 2026
.Dt EXECVE 2
.Os
.Sh NAME
@@ -232,6 +232,17 @@ is to use the
.Dv O_EXEC
flag when opening
.Fa fd .
+Opening without
+.Dv O_EXEC
+may be necessary in the case of executing an interpreted program, as the
+interpreter will not be able to acquire a descriptor to the script for reading
+without mounting
+.Xr fdescfs 4
+on
+.Pa /dev/fd
+with the
+.Cm nodup
+option.
Note that the file to be executed can not be open for writing.
.Sh RETURN VALUES
As the
diff --git a/lib/libsys/intro.2 b/lib/libsys/intro.2
index 008936b278ae..33dfecf648c5 100644
--- a/lib/libsys/intro.2
+++ b/lib/libsys/intro.2
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 19, 2024
+.Dd May 7, 2026
.Dt INTRO 2
.Os
.Sh NAME
@@ -756,7 +756,8 @@ during a system boot.
.El
.Sh SEE ALSO
.Xr intro 3 ,
-.Xr perror 3
+.Xr perror 3 ,
+.Xr dtrace_syscall 4
.Sh HISTORY
The
.Nm Ns Pq 2
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 623b56fb273b..46a2ed5eb8a6 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -119,6 +119,13 @@ enum libusb_endpoint_direction {
#define LIBUSB_TRANSFER_TYPE_MASK 0x03
+enum libusb_endpoint_transfer_type {
+ LIBUSB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0,
+ LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 1,
+ LIBUSB_ENDPOINT_TRANSFER_TYPE_BULK = 2,
+ LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 3,
+};
+
enum libusb_transfer_type {
LIBUSB_TRANSFER_TYPE_CONTROL = 0,
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index b3af017ab980..56c9caedab16 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -1769,14 +1769,14 @@ libusb10_cancel_all_transfer_locked(struct libusb20_device *pdev, struct libusb_
if (sxfer == NULL)
continue;
/* complete pending transfer */
- libusb10_complete_transfer(xfer, sxfer, LIBUSB_TRANSFER_ERROR);
+ libusb10_complete_transfer(xfer, sxfer, LIBUSB_TRANSFER_CANCELLED);
}
while ((sxfer = TAILQ_FIRST(&dev->tr_head))) {
TAILQ_REMOVE(&dev->tr_head, sxfer, entry);
/* complete pending transfer */
- libusb10_complete_transfer(NULL, sxfer, LIBUSB_TRANSFER_ERROR);
+ libusb10_complete_transfer(NULL, sxfer, LIBUSB_TRANSFER_CANCELLED);
}
}
diff --git a/lib/msun/Makefile b/lib/msun/Makefile
index d61f4e9a1659..a9b07babc0a6 100644
--- a/lib/msun/Makefile
+++ b/lib/msun/Makefile
@@ -76,9 +76,11 @@ COMMON_SRCS= b_tgamma.c \
s_finite.c s_finitef.c \
s_floor.c s_floorf.c s_fma.c s_fmaf.c \
s_fmax.c s_fmaxf.c s_fmaximum.c s_fmaximumf.c \
- s_fmaximum_mag.c s_fmaximum_magf.c s_fmaximum_num.c s_fmaximum_numf.c \
+ s_fmaximum_mag.c s_fmaximum_magf.c s_fmaximum_mag_num.c \
+ s_fmaximum_mag_numf.c s_fmaximum_num.c s_fmaximum_numf.c \
s_fmin.c s_fminf.c s_fminimum.c s_fminimumf.c \
- s_fminimum_mag.c s_fminimum_magf.c s_fminimum_num.c s_fminimum_numf.c \
+ s_fminimum_mag.c s_fminimum_magf.c s_fminimum_mag_num.c \
+ s_fminimum_mag_numf.c s_fminimum_num.c s_fminimum_numf.c \
s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \
s_ilogbl.c s_isfinite.c s_isnan.c s_isnormal.c \
s_llrint.c s_llrintf.c s_llround.c s_llroundf.c s_llroundl.c \
@@ -135,8 +137,10 @@ COMMON_SRCS+= b_tgammal.c catrigl.c \
s_asinhl.c s_atanl.c s_cbrtl.c s_ceill.c s_cexpl.c \
s_clogl.c s_cosl.c s_cospil.c s_cprojl.c \
s_csqrtl.c s_erfl.c s_exp2l.c s_expl.c s_floorl.c s_fmal.c \
- s_fmaxl.c s_fmaximuml.c s_fmaximum_magl.c s_fmaximum_numl.c \
- s_fminl.c s_fminimuml.c s_fminimum_magl.c s_fminimum_numl.c \
+ s_fmaxl.c s_fmaximuml.c s_fmaximum_magl.c \
+ s_fmaximum_numl.c s_fmaximum_mag_numl.c \
+ s_fminl.c s_fminimuml.c s_fminimum_magl.c \
+ s_fminimum_numl.c s_fminimum_mag_numl.c \
s_frexpl.c s_logbl.c s_logl.c s_nanl.c \
s_nextafterl.c s_nexttoward.c s_remquol.c s_rintl.c s_roundl.c \
s_scalbnl.c s_sinl.c s_sincosl.c s_sinpil.c \
@@ -182,7 +186,8 @@ MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \
exp.3 fabs.3 fdim.3 \
feclearexcept.3 feenableexcept.3 fegetenv.3 \
fegetround.3 fenv.3 floor.3 fma.3 \
- fmax.3 fmaximum.3 fmaximum_mag.3 fmaximum_num.3 fmod.3 \
+ fmax.3 fmaximum.3 fmaximum_mag.3 \
+ fmaximum_mag_num.3 fmaximum_num.3 fmod.3 \
hypot.3 ieee.3 ieee_test.3 ilogb.3 j0.3 \
lgamma.3 log.3 lrint.3 lround.3 math.3 nan.3 \
nextafter.3 remainder.3 rint.3 \
@@ -242,6 +247,9 @@ MLINKS+=fmaximum.3 fmaximumf.3 fmaximum.3 fmaximuml.3 \
MLINKS+=fmaximum_mag.3 fmaximum_magf.3 fmaximum_mag.3 fmaximum_magl.3 \
fmaximum_mag.3 fminimum_mag.3 fmaximum_mag.3 fminimum_magf.3 \
fmaximum_mag.3 fminimum_magl.3
+MLINKS+=fmaximum_mag_num.3 fmaximum_mag_numf.3 fmaximum_mag_num.3 fmaximum_mag_numl.3 \
+ fmaximum_mag_num.3 fminimum_mag_num.3 fmaximum_mag_num.3 fminimum_mag_numf.3 \
+ fmaximum_mag_num.3 fminimum_mag_numl.3
MLINKS+=fmaximum_num.3 fmaximum_numf.3 fmaximum_num.3 fmaximum_numl.3 \
fmaximum_num.3 fminimum_num.3 fmaximum_num.3 fminimum_numf.3 \
fmaximum_num.3 fminimum_numl.3
diff --git a/lib/msun/Symbol.map b/lib/msun/Symbol.map
index 35addfcee3d5..00222c960f80 100644
--- a/lib/msun/Symbol.map
+++ b/lib/msun/Symbol.map
@@ -323,19 +323,25 @@ FBSD_1.9 {
fmaximum;
fmaximumf;
fmaximuml;
- fminimum;
- fminimumf;
- fminimuml;
fmaximum_mag;
fmaximum_magf;
fmaximum_magl;
- fminimum_mag;
- fminimum_magf;
- fminimum_magl;
+ fmaximum_mag_num;
+ fmaximum_mag_numf;
+ fmaximum_mag_numl;
fmaximum_num;
fmaximum_numf;
fmaximum_numl;
+ fminimum;
+ fminimumf;
+ fminimuml;
+ fminimum_mag;
+ fminimum_magf;
+ fminimum_magl;
fminimum_num;
fminimum_numf;
fminimum_numl;
+ fminimum_mag_num;
+ fminimum_mag_numf;
+ fminimum_mag_numl;
};
diff --git a/lib/msun/man/fmaximum_mag.3 b/lib/msun/man/fmaximum_mag.3
index f5e4c39f96ef..004f9d51daa2 100644
--- a/lib/msun/man/fmaximum_mag.3
+++ b/lib/msun/man/fmaximum_mag.3
@@ -84,7 +84,7 @@ These routines do not raise any floating-point exceptions.
.Sh SEE ALSO
.Xr fmax 3 ,
.Xr fmaximum 3 ,
-.Xr fmaximum_num 3 ,
+.Xr fmaximum_mag_num 3 ,
.Xr math 3
.Sh STANDARDS
The
diff --git a/lib/msun/man/fmaximum_mag_num.3 b/lib/msun/man/fmaximum_mag_num.3
new file mode 100644
index 000000000000..525822bcde27
--- /dev/null
+++ b/lib/msun/man/fmaximum_mag_num.3
@@ -0,0 +1,109 @@
+.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
+.\" Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.Dd April 3, 2026
+.Dt FMAXIMUM_MAG_NUM 3
+.Os
+.Sh NAME
+.Nm fmaximum_mag_num ,
+.Nm fmaximum_mag_numf ,
+.Nm fmaximum_mag_numl ,
+.Nm fminimum_mag_num ,
+.Nm fminimum_mag_numf ,
+.Nm fminimum_mag_numl
+.Nd floating-point maximum and minimum magnitude number functions
+.Sh LIBRARY
+.Lb libm
+.Sh SYNOPSIS
+.In math.h
+.Ft double
+.Fn fmaximum_mag_num "double x" "double y"
+.Ft float
+.Fn fmaximum_mag_numf "float x" "float y"
+.Ft "long double"
+.Fn fmaximum_mag_numl "long double x" "long double y"
+.Ft double
+.Fn fminimum_mag_num "double x" "double y"
+.Ft float
+.Fn fminimum_mag_numf "float x" "float y"
+.Ft "long double"
+.Fn fminimum_mag_numl "long double x" "long double y"
+.Sh DESCRIPTION
+The
+.Fn fmaximum_mag_num ,
+.Fn fmaximum_mag_numf ,
+and
+.Fn fmaximum_mag_numl
+functions determine the larger of the absolute values of
+.Fa x
+and
+.Fa y ,
+and return the argument with the larger absolute value,
+preferring a numeric value over an \*(Na.
+If one argument is a numeric value and the other is an \*(Na,
+the numeric value is returned.
+If the absolute values are equal, the behavior is equivalent to calling the corresponding
+.Fn fmaximum_num
+function on the arguments.
+.Pp
+Likewise, the
+.Fn fminimum_mag_num ,
+.Fn fminimum_mag_numf ,
+and
+.Fn fminimum_mag_numl
+functions determine the smaller of the absolute values of
+.Fa x
+and
+.Fa y ,
+and return the argument with the smaller absolute value,
+preferring a numeric value over an \*(Na.
+If one argument is a numeric value and the other is an \*(Na,
+the numeric value is returned.
+If the absolute values are equal, the behavior is equivalent to calling the corresponding
+.Fn fminimum_num
+function on the arguments.
+.Pp
+If both arguments are \*(Nas, a quiet \*(Na is returned.
+If either argument is a signaling \*(Na, an invalid exception is raised.
+Otherwise, these routines do not raise any floating-point exceptions.
+.Sh SEE ALSO
+.Xr fmax 3 ,
+.Xr fmaximum 3 ,
+.Xr fmaximum_mag 3 ,
+.Xr fmaximum_num 3 ,
+.Xr math 3
+.Sh STANDARDS
+The
+.Fn fmaximum_mag_num ,
+.Fn fmaximum_mag_numf ,
+.Fn fmaximum_mag_numl ,
+.Fn fminimum_mag_num ,
+.Fn fminimum_mag_numf ,
+and
+.Fn fminimum_mag_numl
+functions conform to
+.St -isoC-2023 .
+.Sh HISTORY
+These routines first appeared in
+.Fx 16.0 ..\"
diff --git a/lib/msun/man/math.3 b/lib/msun/man/math.3
index f98c5e1a2a75..882bfdf5225f 100644
--- a/lib/msun/man/math.3
+++ b/lib/msun/man/math.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 11, 2026
+.Dd May 2, 2026
.Dt MATH 3
.Os
.Sh NAME
@@ -117,12 +117,14 @@ fabs absolute value
fdim positive difference
fmax maximum function (legacy)
fmaximum maximum function (prefers \*(Na)
-fmaximum_mag maximum magnitude (prefers \*(Na)
fmaximum_num maximum function (avoids \*(Na)
+fmaximum_mag maximum magnitude (prefers \*(Na)
+fmaximum_mag_num maximum magnitude (avoids \*(Na)
fmin minimum function (legacy)
fminimum minimum function (prefers \*(Na)
-fminimum_mag minimum magnitude (prefers \*(Na)
fminimum_num minimum function (avoids \*(Na)
+fminimum_mag minimum magnitude (prefers \*(Na)
+fminimum_mag_num minimum magnitude (avoids \*(Na)
signbit extract sign bit
.El
.Ss Not a Number Functions
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 853984953a91..9894401160d4 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -523,18 +523,24 @@ long double tanpil(long double);
double fmaximum(double, double);
float fmaximumf(float, float);
long double fmaximuml(long double, long double);
-double fminimum(double, double);
-float fminimumf(float, float);
-long double fminimuml(long double, long double);
double fmaximum_mag(double, double);
float fmaximum_magf(float, float);
long double fmaximum_magl(long double, long double);
-double fminimum_mag(double, double);
-float fminimum_magf(float, float);
-long double fminimum_magl(long double, long double);
+double fmaximum_mag_num(double, double);
+float fmaximum_mag_numf(float, float);
+long double fmaximum_mag_numl(long double, long double);
double fmaximum_num(double, double);
float fmaximum_numf(float, float);
long double fmaximum_numl(long double, long double);
+double fminimum(double, double);
+float fminimumf(float, float);
+long double fminimuml(long double, long double);
+double fminimum_mag(double, double);
+float fminimum_magf(float, float);
+long double fminimum_magl(long double, long double);
+double fminimum_mag_num(double, double);
+float fminimum_mag_numf(float, float);
+long double fminimum_mag_numl(long double, long double);
double fminimum_num(double, double);
float fminimum_numf(float, float);
long double fminimum_numl(long double, long double);
diff --git a/lib/msun/src/s_fmaximum_mag_num.c b/lib/msun/src/s_fmaximum_mag_num.c
new file mode 100644
index 000000000000..fbb8ffbfc250
--- /dev/null
+++ b/lib/msun/src/s_fmaximum_mag_num.c
@@ -0,0 +1,88 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <float.h>
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+#ifdef USE_BUILTIN_FMAXIMUM_MAG_NUM
+double
+fmaximum_mag_num(double x, double y)
+{
+ return (__builtin_fmaximum_mag_num(x, y));
+}
+#else
+double
+fmaximum_mag_num(double x, double y)
+{
+ union IEEEd2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].d = x;
+ u[1].d = y;
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile double force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ double ax = fabs(x);
+ double ay = fabs(y);
+
+ if (ay > ax)
+ return (y);
+ if (ax > ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[u[0].bits.sign].d);
+
+ return (x);
+}
+#endif
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(fmaximum_mag_num, fmaximum_mag_numl);
+#endif
diff --git a/lib/msun/src/s_fmaximum_mag_numf.c b/lib/msun/src/s_fmaximum_mag_numf.c
new file mode 100644
index 000000000000..18232ed5aba8
--- /dev/null
+++ b/lib/msun/src/s_fmaximum_mag_numf.c
@@ -0,0 +1,84 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+#ifdef USE_BUILTIN_FMAXIMUM_MAG_NUMF
+float
+fmaximum_mag_numf(float x, float y)
+{
+ return (__builtin_fmaximum_mag_numf(x, y));
+}
+#else
+float
+fmaximum_mag_numf(float x, float y)
+{
+ union IEEEf2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].f = x;
+ u[1].f = y;
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile float force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ float ax = fabsf(x);
+ float ay = fabsf(y);
+
+ if (ay > ax)
+ return (y);
+ if (ax > ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[u[0].bits.sign].f);
+
+ return (x);
+}
+#endif
+
diff --git a/lib/msun/src/s_fmaximum_mag_numl.c b/lib/msun/src/s_fmaximum_mag_numl.c
new file mode 100644
index 000000000000..eceee8059b03
--- /dev/null
+++ b/lib/msun/src/s_fmaximum_mag_numl.c
@@ -0,0 +1,77 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+long double
+fmaximum_mag_numl(long double x, long double y)
+{
+ union IEEEl2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].e = x;
+ mask_nbit_l(u[0]);
+ u[1].e = y;
+ mask_nbit_l(u[1]);
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile long double force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ long double ax = fabsl(x);
+ long double ay = fabsl(y);
+
+ if (ay > ax)
+ return (y);
+ if (ax > ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[0].bits.sign ? y : x);
+
+ return (x);
+}
diff --git a/lib/msun/src/s_fmaximum_num.c b/lib/msun/src/s_fmaximum_num.c
index c7cfcd26fd70..4d7c860d2ce9 100644
--- a/lib/msun/src/s_fmaximum_num.c
+++ b/lib/msun/src/s_fmaximum_num.c
@@ -53,12 +53,18 @@ fmaximum_num(double x, double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile double force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/src/s_fmaximum_numf.c b/lib/msun/src/s_fmaximum_numf.c
index 60a7ccae343e..b41f293a428d 100644
--- a/lib/msun/src/s_fmaximum_numf.c
+++ b/lib/msun/src/s_fmaximum_numf.c
@@ -52,12 +52,18 @@ fmaximum_numf(float x, float y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile float force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/src/s_fmaximum_numl.c b/lib/msun/src/s_fmaximum_numl.c
index a2a5383ab85a..74a3d9ba2211 100644
--- a/lib/msun/src/s_fmaximum_numl.c
+++ b/lib/msun/src/s_fmaximum_numl.c
@@ -47,12 +47,18 @@ fmaximum_numl(long double x, long double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile long double force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/src/s_fminimum_mag_num.c b/lib/msun/src/s_fminimum_mag_num.c
new file mode 100644
index 000000000000..b5f62837f1b4
--- /dev/null
+++ b/lib/msun/src/s_fminimum_mag_num.c
@@ -0,0 +1,90 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <float.h>
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+#ifdef USE_BUILTIN_FMINIMUM_MAG_NUM
+double
+fminimum_mag_num(double x, double y)
+{
+ return (__builtin_fminimum_mag_num(x, y));
+}
+#else
+double
+fminimum_mag_num(double x, double y)
+{
+ union IEEEd2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].d = x;
+ u[1].d = y;
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile double force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ double ax = fabs(x);
+ double ay = fabs(y);
+
+ if (ay < ax)
+ return (y);
+ if (ax < ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[u[1].bits.sign].d);
+
+ return (x);
+}
+#endif
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(fminimum_mag_num, fminimum_mag_numl);
+#endif
+
+
diff --git a/lib/msun/src/s_fminimum_mag_numf.c b/lib/msun/src/s_fminimum_mag_numf.c
new file mode 100644
index 000000000000..b8cb31f2315a
--- /dev/null
+++ b/lib/msun/src/s_fminimum_mag_numf.c
@@ -0,0 +1,85 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+#ifdef USE_BUILTIN_FMINIMUM_MAG_NUMF
+float
+fminimum_mag_numf(float x, float y)
+{
+ return (__builtin_fminimum_mag_numf(x, y));
+}
+#else
+float
+fminimum_mag_numf(float x, float y)
+{
+ union IEEEf2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].f = x;
+ u[1].f = y;
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile float force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ float ax = fabsf(x);
+ float ay = fabsf(y);
+
+ if (ay < ax)
+ return (y);
+ if (ax < ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[u[1].bits.sign].f);
+
+ return (x);
+}
+#endif
+
+
diff --git a/lib/msun/src/s_fminimum_mag_numl.c b/lib/msun/src/s_fminimum_mag_numl.c
new file mode 100644
index 000000000000..1d001e84b618
--- /dev/null
+++ b/lib/msun/src/s_fminimum_mag_numl.c
@@ -0,0 +1,79 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2026 Jesús Blázquez <jesuscblazquez@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <stdbool.h>
+
+#include "fpmath.h"
+
+long double
+fminimum_mag_numl(long double x, long double y)
+{
+ union IEEEl2bits u[2];
+ bool nan_x, nan_y;
+
+ u[0].e = x;
+ mask_nbit_l(u[0]);
+ u[1].e = y;
+ mask_nbit_l(u[1]);
+
+ nan_x = isnan(x);
+ nan_y = isnan(y);
+
+ if (nan_x || nan_y) {
+ /* If both are NaN, adding returns qNaN */
+ if (nan_x && nan_y)
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile long double force_except = x + y;
+ force_except;
+
+ if (nan_x)
+ return (y);
+ else
+ return (x);
+ }
+
+ long double ax = fabsl(x);
+ long double ay = fabsl(y);
+
+ if (ay < ax)
+ return (y);
+ if (ax < ay)
+ return (x);
+
+ /* If magnitudes are equal, we break the tie with the sign */
+ if (u[0].bits.sign != u[1].bits.sign)
+ return (u[1].bits.sign ? y : x);
+
+ return (x);
+}
+
+
diff --git a/lib/msun/src/s_fminimum_num.c b/lib/msun/src/s_fminimum_num.c
index a5fd657955c5..67999c366a76 100644
--- a/lib/msun/src/s_fminimum_num.c
+++ b/lib/msun/src/s_fminimum_num.c
@@ -53,12 +53,18 @@ fminimum_num(double x, double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile double force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/src/s_fminimum_numf.c b/lib/msun/src/s_fminimum_numf.c
index d5e8f0812bdb..c4b686be158e 100644
--- a/lib/msun/src/s_fminimum_numf.c
+++ b/lib/msun/src/s_fminimum_numf.c
@@ -52,12 +52,18 @@ fminimum_numf(float x, float y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile float force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/src/s_fminimum_numl.c b/lib/msun/src/s_fminimum_numl.c
index dc0884002499..b30fbc721b6b 100644
--- a/lib/msun/src/s_fminimum_numl.c
+++ b/lib/msun/src/s_fminimum_numl.c
@@ -47,12 +47,18 @@ fminimum_numl(long double x, long double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
- /* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
+ /* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
- return (x + y);
+ return (x + y);
+
+ /* force_except makes sure sNaN's raise exceptions */
+ volatile long double force_except = x + y;
+ force_except;
+
if (nan_x)
- return ((x + y) != 0.0 ? y : y);
- return ((x + y) != 0.0 ? x : x);
+ return (y);
+ else
+ return (x);
}
/* Handle comparisons of signed zeroes. */
diff --git a/lib/msun/tests/fmaximum_fminimum_test.c b/lib/msun/tests/fmaximum_fminimum_test.c
index 4c8ec9a5b0e0..0d97c4be8d8c 100644
--- a/lib/msun/tests/fmaximum_fminimum_test.c
+++ b/lib/msun/tests/fmaximum_fminimum_test.c
@@ -27,7 +27,8 @@
/*
* Tests for fmaximum{,f,l}(), fminimum{,f,l}(), fmaximum_mag{,f,l},
- * fminimum_mag{,f,l}, fmaximum_num{,f,l}, fminimum_num{,f,l}
+ * fminimum_mag{,f,l}, fmaximum_num{,f,l}, fminimum_num{,f,l},
+ * fmaximum_mag_num{,f,l} and fminimum_mag_num{,f,l}
*/
#include <sys/cdefs.h>
@@ -130,6 +131,30 @@ testall_num_r(long double big, long double small, int rmode) {
TEST(fminimum_numl, long double, small, big, expected_min_num, rmode);
}
+static void
+testall_mag_num_r(long double big, long double small, int rmode) {
+ long double expected_max_mag_num = isnan(big) ? small : big;
+ long double expected_min_mag_num = isnan(small) ? big : small;
+
+ if (fabsl(small) > fabsl(big)) {
+ expected_max_mag_num = small;
+ expected_min_mag_num = big;
+ }
+
+ TEST(fmaximum_mag_numf, float, big, small, expected_max_mag_num, rmode);
+ TEST(fmaximum_mag_numf, float, small, big, expected_max_mag_num, rmode);
+ TEST(fmaximum_mag_num, double, big, small, expected_max_mag_num, rmode);
+ TEST(fmaximum_mag_num, double, small, big, expected_max_mag_num, rmode);
+ TEST(fmaximum_mag_numl, long double, big, small, expected_max_mag_num, rmode);
+ TEST(fmaximum_mag_numl, long double, small, big, expected_max_mag_num, rmode);
+ TEST(fminimum_mag_numf, float, big, small, expected_min_mag_num, rmode);
+ TEST(fminimum_mag_numf, float, small, big, expected_min_mag_num, rmode);
+ TEST(fminimum_mag_num, double, big, small, expected_min_mag_num, rmode);
+ TEST(fminimum_mag_num, double, small, big, expected_min_mag_num, rmode);
+ TEST(fminimum_mag_numl, long double, big, small, expected_min_mag_num, rmode);
+ TEST(fminimum_mag_numl, long double, small, big, expected_min_mag_num, rmode);
+}
+
/*
* Test all the functions: fmaximumf, fmaximum, fmaximuml, fminimumf, fminimum, fminimuml
* in all rounding modes and with the arguments in different orders.
@@ -148,6 +173,7 @@ testall(long double big, long double small)
testall_r(big, small, rmodes[i]);
testall_mag_r(big, small, rmodes[i]);
testall_num_r(big, small, rmodes[i]);
+ testall_mag_num_r(big, small, rmodes[i]);
}
}