]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add setpayload, setpayloadf, setpayloadl.
authorJoseph Myers <joseph@codesourcery.com>
Sat, 19 Nov 2016 00:16:28 +0000 (00:16 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Sat, 19 Nov 2016 00:16:28 +0000 (00:16 +0000)
TS 18661-1 defines functions for manipulating the payloads of NaNs.
This patch implements the setpayload functions for glibc; these set a
number (pointed to by a function argument) to a quiet NaN with the
given payload, or to +0 if the given payload is not valid.  The
implementations are structured to allow the substance of the
implementation to be shared with the setpayloadsig functions when
those are added.

The semantics in the TS are not entirely clear in the case where the
payload passed to the function is zero (see discussion on the WG14
reflector last month).  This patch implements what seems the most
sensible interpretation, that -0 is never valid to give as the
payload, but +0 is valid in the case where the kind of NaN being
generated has its high mantissa bit set so payload 0 is actually
possible in such a NaN.

Tested for x86_64, x86, mips64 and powerpc.

* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
(setpayload): New declaration.
* math/Versions (setpayload): New libm symbol at version
GLIBC_2.25.
(setpayloadf): Likewise.
(setpayloadl): Likewise.
* math/Makefile (libm-calls): Add s_setpayloadF.
* math/libm-test.inc (struct test_Ffp_b1_data): Rename to struct
test_Ff_b1_data.
(RUN_TEST_Ff_b1): New macro.
(RUN_TEST_LOOP_Ff_b1): Likewise.
(canonicalize_test_data): Update type.
(setpayload_test_data): New array.
(setpayload_test): New function.
(main): Call setpayload_test.
* manual/arith.texi (FP Bit Twiddling): Document setpayload,
setpayloadf and setpayloadl.
* manual/libm-err-tab.pl: Update comment on interfaces without
ulps tabulated.
* sysdeps/ieee754/dbl-64/s_setpayload.c: New file.
* sysdeps/ieee754/dbl-64/s_setpayload_main.c: Likewise.
* sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c:
Likewise.
* sysdeps/ieee754/flt-32/s_setpayloadf.c: Likewise.
* sysdeps/ieee754/flt-32/s_setpayloadf_main.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_setpayloadl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_setpayloadl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c: Likewise.
* sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c: Likewise.
* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
setpayload.
(CFLAGS-nldbl-setpayload.c): New variable.
* sysdeps/nacl/libm.abilist: Update.
* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.

48 files changed:
ChangeLog
NEWS
manual/arith.texi
manual/libm-err-tab.pl
math/Makefile
math/Versions
math/bits/mathcalls.h
math/libm-test.inc
sysdeps/ieee754/dbl-64/s_setpayload.c [new file with mode: 0644]
sysdeps/ieee754/dbl-64/s_setpayload_main.c [new file with mode: 0644]
sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c [new file with mode: 0644]
sysdeps/ieee754/flt-32/s_setpayloadf.c [new file with mode: 0644]
sysdeps/ieee754/flt-32/s_setpayloadf_main.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-128/s_setpayloadl.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-96/s_setpayloadl.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-opt/Makefile
sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c [new file with mode: 0644]
sysdeps/nacl/libm.abilist
sysdeps/unix/sysv/linux/aarch64/libm.abilist
sysdeps/unix/sysv/linux/alpha/libm.abilist
sysdeps/unix/sysv/linux/arm/libm.abilist
sysdeps/unix/sysv/linux/hppa/libm.abilist
sysdeps/unix/sysv/linux/i386/libm.abilist
sysdeps/unix/sysv/linux/ia64/libm.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist
sysdeps/unix/sysv/linux/microblaze/libm.abilist
sysdeps/unix/sysv/linux/mips/mips32/libm.abilist
sysdeps/unix/sysv/linux/mips/mips64/libm.abilist
sysdeps/unix/sysv/linux/nios2/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist
sysdeps/unix/sysv/linux/sh/libm.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist
sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist
sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist
sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist
sysdeps/unix/sysv/linux/x86_64/64/libm.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist

index b923ac9acfa09e063dec0bcdea5f660660a71ff4..a3ea6a84d958517458be952729d9e12f8b486e42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,74 @@
+2016-11-19  Joseph Myers  <joseph@codesourcery.com>
+
+       * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
+       (setpayload): New declaration.
+       * math/Versions (setpayload): New libm symbol at version
+       GLIBC_2.25.
+       (setpayloadf): Likewise.
+       (setpayloadl): Likewise.
+       * math/Makefile (libm-calls): Add s_setpayloadF.
+       * math/libm-test.inc (struct test_Ffp_b1_data): Rename to struct
+       test_Ff_b1_data.
+       (RUN_TEST_Ff_b1): New macro.
+       (RUN_TEST_LOOP_Ff_b1): Likewise.
+       (canonicalize_test_data): Update type.
+       (setpayload_test_data): New array.
+       (setpayload_test): New function.
+       (main): Call setpayload_test.
+       * manual/arith.texi (FP Bit Twiddling): Document setpayload,
+       setpayloadf and setpayloadl.
+       * manual/libm-err-tab.pl: Update comment on interfaces without
+       ulps tabulated.
+       * sysdeps/ieee754/dbl-64/s_setpayload.c: New file.
+       * sysdeps/ieee754/dbl-64/s_setpayload_main.c: Likewise.
+       * sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c:
+       Likewise.
+       * sysdeps/ieee754/flt-32/s_setpayloadf.c: Likewise.
+       * sysdeps/ieee754/flt-32/s_setpayloadf_main.c: Likewise.
+       * sysdeps/ieee754/ldbl-128/s_setpayloadl.c: Likewise.
+       * sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c: Likewise.
+       * sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c: Likewise.
+       * sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c: Likewise.
+       * sysdeps/ieee754/ldbl-96/s_setpayloadl.c: Likewise.
+       * sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c: Likewise.
+       * sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c: Likewise.
+       * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
+       setpayload.
+       (CFLAGS-nldbl-setpayload.c): New variable.
+       * sysdeps/nacl/libm.abilist: Update.
+       * sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
+
 2016-11-18  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        * hurd/hurd.h (__hurd_fail_noerrno): Remove function.
diff --git a/NEWS b/NEWS
index 65184b11da594d4d06ddc118efbcce3893dfa190..b99fc69248dda593a4b334df337b2d41d1015458 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -62,7 +62,8 @@ Version 2.25
 
   - Canonicalize functions: canonicalize, canonicalizef, canonicalizel.
 
-  - NaN functions: getpayload, getpayloadf, getpayloadl.
+  - NaN functions: getpayload, getpayloadf, getpayloadl, setpayload,
+    setpayloadf, setpayloadl.
 
 * The functions strfromd, strfromf, and strfroml, from ISO/IEC TS 18661-1:2014,
   are added to libc.  They convert a floating-point number into string.
index f0f3bb40311f775e41ec64fa5bb869958dc967b1..07dd733844850096d83e86a712d13fc4fb423fb6 100644 (file)
@@ -1914,6 +1914,24 @@ integer, or positive zero, represented as a floating-point number); if
 floating-point exceptions even for signaling NaNs.
 @end deftypefun
 
+@comment math.h
+@comment ISO
+@deftypefun int setpayload (double *@var{x}, double @var{payload})
+@comment math.h
+@comment ISO
+@deftypefunx int setpayloadf (float *@var{x}, float @var{payload})
+@comment math.h
+@comment ISO
+@deftypefunx int setpayloadl (long double *@var{x}, long double @var{payload})
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+These functions, defined by TS 18661-1:2014, set the object pointed to
+by @var{x} to a quiet NaN with payload @var{payload} and a zero sign
+bit and return zero.  If @var{payload} is not a positive-signed
+integer that is a valid payload for a quiet NaN of the given type, the
+object pointed to by @var{x} is set to positive zero and a nonzero
+value is returned.  They raise no floating-point exceptions.
+@end deftypefun
+
 @node FP Comparison Functions
 @subsection Floating-Point Comparison Functions
 @cindex unordered comparison
index 3ea62c549e883c5b846f9e0450988ccd927a1ee7..146460675f289820c0209bf9d3e6489dda4ddcd6 100755 (executable)
@@ -67,7 +67,7 @@ use vars qw (%results @all_floats %suffices @all_functions);
 # canonicalize, fpclassify, getpayload, iscanonical, isnormal,
 # isfinite, isinf, isnan, issignaling, issubnormal, iszero, signbit,
 # iseqsig, isgreater, isgreaterequal, isless, islessequal,
-# islessgreater, isunordered, totalorder, totalordermag
+# islessgreater, isunordered, setpayload, totalorder, totalordermag
 # are not tabulated.
 
 if ($#ARGV == 0) {
index f400d7b74156562fac301bbe8989f3d85e215a01..a5b11e9177a12541f8f28ebafc0d4bc5c5ff7b22 100644 (file)
@@ -73,7 +73,7 @@ libm-calls =                                                            \
        s_issignalingF $(calls:s_%=m_%) x2y2m1F                           \
        gamma_productF lgamma_negF lgamma_productF                        \
        s_nextupF s_totalorderF s_totalordermagF s_getpayloadF            \
-       $(gen-libm-calls)
+       s_setpayloadF $(gen-libm-calls)
 
 libm-compat-calls-ldouble-yes = w_lgamma_compatl k_standardl
 libm-compat-calls = w_lgamma_compatf w_lgamma_compat k_standard k_standardf \
index 0cd594b3781b9b5034e1b69e25c3c7168fe2b14e..4e15aea9cc0d83766b259aab1554887be618159c 100644 (file)
@@ -221,5 +221,6 @@ libm {
     totalordermag; totalordermagf; totalordermagl;
     getpayload; getpayloadf; getpayloadl;
     canonicalize; canonicalizef; canonicalizel;
+    setpayload; setpayloadf; setpayloadl;
   }
 }
index 2fd1d289dae8389c06d1e86ca4991f1155df591f..0f4e625928fe47a38588fb4b7844e5111ffed69f 100644 (file)
@@ -400,6 +400,9 @@ __MATHDECL_1 (int, canonicalize,, (_Mdouble_ *__cx, const _Mdouble_ *__x));
 
 /* Get NaN payload.  */
 __MATHCALL (getpayload,, (const _Mdouble_ *__x));
+
+/* Set quiet NaN payload.  */
+__MATHDECL_1 (int, setpayload,, (_Mdouble_ *__x, _Mdouble_ __payload));
 #endif
 
 #if defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
index 88420ee613b31c73f2e60b6a207ea9553c734403..602a8e242dfba4c7fdd383fa17ad1efdbe3e99a9 100644 (file)
@@ -54,7 +54,7 @@
    modf, nearbyint, nextafter, nexttoward,
    pow, pow10, remainder, remquo, rint, lrint, llrint,
    round, lround, llround,
-   scalb, scalbn, scalbln, signbit, sin, sincos, sinh, sqrt,
+   scalb, scalbn, scalbln, setpayload, signbit, sin, sincos, sinh, sqrt,
    tan, tanh, tgamma, totalorder, totalordermag, trunc,
    y0, y1, yn, significand
 
@@ -1298,7 +1298,8 @@ struct test_fFF_11_data
     FLOAT extra2_expected;
   } rd, rn, rz, ru;
 };
-struct test_Ffp_b1_data
+/* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1.  */
+struct test_Ff_b1_data
 {
   const char *arg_str;
   FLOAT arg;
@@ -1583,6 +1584,36 @@ struct test_Ffp_b1_data
                            (ARRAY)[i].RM_##ROUNDING_MODE.extra_test,   \
                            (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
   ROUND_RESTORE_ ## ROUNDING_MODE
+#define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED,              \
+                      EXCEPTIONS, EXTRA_VAR, EXTRA_TEST,               \
+                      EXTRA_EXPECTED)                                  \
+  do                                                                   \
+    if (enable_test (EXCEPTIONS))                                      \
+      {                                                                        \
+       COMMON_TEST_SETUP (ARG_STR);                                    \
+       (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0;                    \
+       check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR),     \
+                                                     (ARG)),           \
+                   EXPECTED, EXCEPTIONS);                              \
+       EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1);                           \
+       if (EXTRA_TEST)                                                 \
+         check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED,          \
+                      (EXCEPTIONS) & TEST_NAN_PAYLOAD);                \
+       EXTRA_OUTPUT_TEST_CLEANUP (1);                                  \
+       COMMON_TEST_CLEANUP;                                            \
+      }                                                                        \
+  while (0)
+#define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE,           \
+                           EXTRA_VAR)                                  \
+  IF_ROUND_INIT_ ## ROUNDING_MODE                                      \
+    for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++)    \
+      RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg,   \
+                     (ARRAY)[i].RM_##ROUNDING_MODE.expected,           \
+                     (ARRAY)[i].RM_##ROUNDING_MODE.exceptions,         \
+                     EXTRA_VAR,                                        \
+                     (ARRAY)[i].RM_##ROUNDING_MODE.extra_test,         \
+                     (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected);    \
+  ROUND_RESTORE_ ## ROUNDING_MODE
 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED,             \
                        EXCEPTIONS, EXTRA_VAR, EXTRA_TEST,              \
                        EXTRA_EXPECTED)                                 \
@@ -3620,7 +3651,7 @@ cacosh_test (void)
 }
 
 
-static const struct test_Ffp_b1_data canonicalize_test_data[] =
+static const struct test_Ff_b1_data canonicalize_test_data[] =
   {
     TEST_Ffp_b1 (canonicalize, plus_infty, 0, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_Ffp_b1 (canonicalize, minus_infty, 0, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
@@ -12304,6 +12335,88 @@ scalbln_test (void)
 }
 
 
+static const struct test_Ff_b1_data setpayload_test_data[] =
+  {
+#if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
+    TEST_Ff_b1 (setpayload, plus_zero, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#else
+    TEST_Ff_b1 (setpayload, plus_zero, 0, qnan_value_pl ("0x0"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#endif
+    TEST_Ff_b1 (setpayload, 0x1p0, 0, qnan_value_pl ("0x1"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+    TEST_Ff_b1 (setpayload, 0x2p0, 0, qnan_value_pl ("0x2"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+    TEST_Ff_b1 (setpayload, 0x3fffffp0, 0, qnan_value_pl ("0x3fffff"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#if PAYLOAD_DIG >= 51
+    TEST_Ff_b1 (setpayload, 0x7ffffffffffffp0, 0, qnan_value_pl ("0x7ffffffffffff"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x7ffffffffffffp0, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if PAYLOAD_DIG >= 62
+    TEST_Ff_b1 (setpayload, 0x3fffffffffffffffp0, 0, qnan_value_pl ("0x3fffffffffffffff"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x3fffffffffffffffp0, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if PAYLOAD_DIG >= 111
+    TEST_Ff_b1 (setpayload, 0x7fffffffffffffffffffffffffffp0, 0, qnan_value_pl ("0x7fffffffffffffffffffffffffff"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x7fffffffffffffffffffffffffffp0, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+    TEST_Ff_b1 (setpayload, minus_zero, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -1.0, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -2.0, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, 0.5, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -0.5, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, max_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -max_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, min_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -min_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, min_subnorm_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -min_subnorm_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, plus_infty, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, minus_infty, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, qnan_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -qnan_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, snan_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, -snan_value, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_Ff_b1 (setpayload, 0xffffffp-1, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#if MANT_DIG >= 53
+    TEST_Ff_b1 (setpayload, 0x1fffffffffffffp-1, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if MANT_DIG >= 64
+    TEST_Ff_b1 (setpayload, 0xffffffffffffffffp-1, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if MANT_DIG >= 106
+    TEST_Ff_b1 (setpayload, 0x3ffffffffffffffffffffffffffp-1, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if MANT_DIG >= 113
+    TEST_Ff_b1 (setpayload, 0x1ffffffffffffffffffffffffffffp-1, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if PAYLOAD_DIG >= 23
+    TEST_Ff_b1 (setpayload, 0x1p22, 0, qnan_value_pl ("0x400000"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x1p22, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if PAYLOAD_DIG >= 52
+    TEST_Ff_b1 (setpayload, 0x1p51, 0, qnan_value_pl ("0x8000000000000"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x1p51, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+#if PAYLOAD_DIG >= 63
+    TEST_Ff_b1 (setpayload, 0x1p62, 0, qnan_value_pl ("0x4000000000000000"), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|TEST_NAN_SIGN|TEST_NAN_PAYLOAD),
+#else
+    TEST_Ff_b1 (setpayload, 0x1p62, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
+    TEST_Ff_b1 (setpayload, 0x1p111, 1, plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+
+static void
+setpayload_test (void)
+{
+  FLOAT x;
+
+  ALL_RM_TEST (setpayload, 1, setpayload_test_data, RUN_TEST_LOOP_Ff_b1, END, x);
+}
+
+
 static const struct test_f_i_data signbit_test_data[] =
   {
     TEST_f_b (signbit, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
@@ -13646,6 +13759,7 @@ main (int argc, char **argv)
 
   /* NaN functions:  */
   getpayload_test ();
+  setpayload_test ();
 
   /* Complex functions:  */
   cabs_test ();
diff --git a/sysdeps/ieee754/dbl-64/s_setpayload.c b/sysdeps/ieee754/dbl-64/s_setpayload.c
new file mode 100644 (file)
index 0000000..5ab70de
--- /dev/null
@@ -0,0 +1,6 @@
+#define SIG 0
+#define FUNC setpayload
+#include <s_setpayload_main.c>
+#ifdef NO_LONG_DOUBLE
+weak_alias (setpayload, setpayloadl)
+#endif
diff --git a/sysdeps/ieee754/dbl-64/s_setpayload_main.c b/sysdeps/ieee754/dbl-64/s_setpayload_main.c
new file mode 100644 (file)
index 0000000..d7a3609
--- /dev/null
@@ -0,0 +1,69 @@
+/* Set NaN payload.  dbl-64 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x3ff
+#define PAYLOAD_DIG 51
+#define EXPLICIT_MANT_DIG 52
+
+int
+FUNC (double *x, double payload)
+{
+  uint32_t hx, lx;
+  EXTRACT_WORDS (hx, lx, payload);
+  int exponent = hx >> (EXPLICIT_MANT_DIG - 32);
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  */
+  if (exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT && hx == 0 && lx == 0)))
+    {
+      INSERT_WORDS (*x, 0, 0);
+      return 1;
+    }
+  int shift = BIAS + EXPLICIT_MANT_DIG - exponent;
+  if (shift < 32
+      ? (lx & ((1U << shift) - 1)) != 0
+      : (lx != 0 || (hx & ((1U << (shift - 32)) - 1)) != 0))
+    {
+      INSERT_WORDS (*x, 0, 0);
+      return 1;
+    }
+  if (exponent != 0)
+    {
+      hx &= (1U << (EXPLICIT_MANT_DIG - 32)) - 1;
+      hx |= 1U << (EXPLICIT_MANT_DIG - 32);
+      if (shift >= 32)
+       {
+         lx = hx >> (shift - 32);
+         hx = 0;
+       }
+      else if (shift != 0)
+       {
+         lx = (lx >> shift) | (hx << (32 - shift));
+         hx >>= shift;
+       }
+    }
+  hx |= 0x7ff00000 | (SET_HIGH_BIT ? 0x80000 : 0);
+  INSERT_WORDS (*x, hx, lx);
+  return 0;
+}
diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c
new file mode 100644 (file)
index 0000000..6915792
--- /dev/null
@@ -0,0 +1,53 @@
+/* Set NaN payload.  dbl-64/wordsize-64 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x3ff
+#define PAYLOAD_DIG 51
+#define EXPLICIT_MANT_DIG 52
+
+int
+FUNC (double *x, double payload)
+{
+  uint64_t ix;
+  EXTRACT_WORDS64 (ix, payload);
+  int exponent = ix >> EXPLICIT_MANT_DIG;
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  */
+  if (exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
+      || (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
+    {
+      INSERT_WORDS64 (*x, 0);
+      return 1;
+    }
+  if (ix != 0)
+    {
+      ix &= (1ULL << EXPLICIT_MANT_DIG) - 1;
+      ix |= 1ULL << EXPLICIT_MANT_DIG;
+      ix >>= BIAS + EXPLICIT_MANT_DIG - exponent;
+    }
+  ix |= 0x7ff0000000000000ULL | (SET_HIGH_BIT ? 0x8000000000000ULL : 0);
+  INSERT_WORDS64 (*x, ix);
+  return 0;
+}
diff --git a/sysdeps/ieee754/flt-32/s_setpayloadf.c b/sysdeps/ieee754/flt-32/s_setpayloadf.c
new file mode 100644 (file)
index 0000000..86dfda9
--- /dev/null
@@ -0,0 +1,3 @@
+#define SIG 0
+#define FUNC setpayloadf
+#include <s_setpayloadf_main.c>
diff --git a/sysdeps/ieee754/flt-32/s_setpayloadf_main.c b/sysdeps/ieee754/flt-32/s_setpayloadf_main.c
new file mode 100644 (file)
index 0000000..cd40294
--- /dev/null
@@ -0,0 +1,53 @@
+/* Set NaN payload.  flt-32 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x7f
+#define PAYLOAD_DIG 22
+#define EXPLICIT_MANT_DIG 23
+
+int
+FUNC (float *x, float payload)
+{
+  uint32_t ix;
+  GET_FLOAT_WORD (ix, payload);
+  int exponent = ix >> EXPLICIT_MANT_DIG;
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  */
+  if (exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
+      || (ix & ((1U << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
+    {
+      SET_FLOAT_WORD (*x, 0);
+      return 1;
+    }
+  if (ix != 0)
+    {
+      ix &= (1U << EXPLICIT_MANT_DIG) - 1;
+      ix |= 1U << EXPLICIT_MANT_DIG;
+      ix >>= BIAS + EXPLICIT_MANT_DIG - exponent;
+    }
+  ix |= 0x7f800000 | (SET_HIGH_BIT ? 0x400000 : 0);
+  SET_FLOAT_WORD (*x, ix);
+  return 0;
+}
diff --git a/sysdeps/ieee754/ldbl-128/s_setpayloadl.c b/sysdeps/ieee754/ldbl-128/s_setpayloadl.c
new file mode 100644 (file)
index 0000000..1aba33e
--- /dev/null
@@ -0,0 +1,3 @@
+#define SIG 0
+#define FUNC setpayloadl
+#include <s_setpayloadl_main.c>
diff --git a/sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c b/sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c
new file mode 100644 (file)
index 0000000..5f54811
--- /dev/null
@@ -0,0 +1,69 @@
+/* Set NaN payload.  ldbl-128 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x3fff
+#define PAYLOAD_DIG 111
+#define EXPLICIT_MANT_DIG 112
+
+int
+FUNC (long double *x, long double payload)
+{
+  uint64_t hx, lx;
+  GET_LDOUBLE_WORDS64 (hx, lx, payload);
+  int exponent = hx >> (EXPLICIT_MANT_DIG - 64);
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  */
+  if (exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT && hx == 0 && lx == 0)))
+    {
+      SET_LDOUBLE_WORDS64 (*x, 0, 0);
+      return 1;
+    }
+  int shift = BIAS + EXPLICIT_MANT_DIG - exponent;
+  if (shift < 64
+      ? (lx & ((1ULL << shift) - 1)) != 0
+      : (lx != 0 || (hx & ((1ULL << (shift - 64)) - 1)) != 0))
+    {
+      SET_LDOUBLE_WORDS64 (*x, 0, 0);
+      return 1;
+    }
+  if (exponent != 0)
+    {
+      hx &= (1ULL << (EXPLICIT_MANT_DIG - 64)) - 1;
+      hx |= 1ULL << (EXPLICIT_MANT_DIG - 64);
+      if (shift >= 64)
+       {
+         lx = hx >> (shift - 64);
+         hx = 0;
+       }
+      else if (shift != 0)
+       {
+         lx = (lx >> shift) | (hx << (64 - shift));
+         hx >>= shift;
+       }
+    }
+  hx |= 0x7fff000000000000ULL | (SET_HIGH_BIT ? 0x800000000000ULL : 0);
+  SET_LDOUBLE_WORDS64 (*x, hx, lx);
+  return 0;
+}
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c b/sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c
new file mode 100644 (file)
index 0000000..1aba33e
--- /dev/null
@@ -0,0 +1,3 @@
+#define SIG 0
+#define FUNC setpayloadl
+#include <s_setpayloadl_main.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c b/sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c
new file mode 100644 (file)
index 0000000..278306f
--- /dev/null
@@ -0,0 +1,60 @@
+/* Set NaN payload.  ldbl-128ibm version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x3ff
+#define PAYLOAD_DIG 51
+#define EXPLICIT_MANT_DIG 52
+
+int
+FUNC (long double *x, long double payload)
+{
+  double hi, lo;
+  uint64_t hx, lx;
+
+  ldbl_unpack (payload, &hi, &lo);
+  EXTRACT_WORDS64 (hx, hi);
+  EXTRACT_WORDS64 (lx, lo);
+  int exponent = hx >> EXPLICIT_MANT_DIG;
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  All valid
+     arguments have the low part zero.  */
+  if ((lx & 0x7fffffffffffffffULL) != 0
+      || exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT && hx == 0))
+      || (hx & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
+    {
+      *x = 0.0L;
+      return 1;
+    }
+  if (hx != 0)
+    {
+      hx &= (1ULL << EXPLICIT_MANT_DIG) - 1;
+      hx |= 1ULL << EXPLICIT_MANT_DIG;
+      hx >>= BIAS + EXPLICIT_MANT_DIG - exponent;
+    }
+  hx |= 0x7ff0000000000000ULL | (SET_HIGH_BIT ? 0x8000000000000ULL : 0);
+  INSERT_WORDS64 (hi, hx);
+  *x = ldbl_pack (hi, 0.0);
+  return 0;
+}
diff --git a/sysdeps/ieee754/ldbl-96/s_setpayloadl.c b/sysdeps/ieee754/ldbl-96/s_setpayloadl.c
new file mode 100644 (file)
index 0000000..1aba33e
--- /dev/null
@@ -0,0 +1,3 @@
+#define SIG 0
+#define FUNC setpayloadl
+#include <s_setpayloadl_main.c>
diff --git a/sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c b/sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c
new file mode 100644 (file)
index 0000000..9af967b
--- /dev/null
@@ -0,0 +1,68 @@
+/* Set NaN payload.  ldbl-96 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <nan-high-order-bit.h>
+#include <stdint.h>
+
+#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
+#define BIAS 0x3fff
+#define PAYLOAD_DIG 62
+#define EXPLICIT_MANT_DIG 63
+
+int
+FUNC (long double *x, long double payload)
+{
+  uint32_t hx, lx;
+  uint16_t exponent;
+  GET_LDOUBLE_WORDS (exponent, hx, lx, payload);
+  /* Test if argument is (a) negative or too large; (b) too small,
+     except for 0 when allowed; (c) not an integer.  */
+  if (exponent >= BIAS + PAYLOAD_DIG
+      || (exponent < BIAS && !(SET_HIGH_BIT
+                              && exponent == 0 && hx == 0 && lx == 0)))
+    {
+      SET_LDOUBLE_WORDS (*x, 0, 0, 0);
+      return 1;
+    }
+  int shift = BIAS + EXPLICIT_MANT_DIG - exponent;
+  if (shift < 32
+      ? (lx & ((1U << shift) - 1)) != 0
+      : (lx != 0 || (hx & ((1U << (shift - 32)) - 1)) != 0))
+    {
+      SET_LDOUBLE_WORDS (*x, 0, 0, 0);
+      return 1;
+    }
+  if (exponent != 0)
+    {
+      if (shift >= 32)
+       {
+         lx = hx >> (shift - 32);
+         hx = 0;
+       }
+      else if (shift != 0)
+       {
+         lx = (lx >> shift) | (hx << (32 - shift));
+         hx >>= shift;
+       }
+    }
+  hx |= 0x80000000 | (SET_HIGH_BIT ? 0x40000000 : 0);
+  SET_LDOUBLE_WORDS (*x, 0x7fff, hx, lx);
+  return 0;
+}
index 745fa4c8cfc7f2c8773fac6e237dc6eb942a698b..627ebc8b55b635ae74c2087f0c0e330fc03f92a3 100644 (file)
@@ -43,7 +43,7 @@ libnldbl-calls = asprintf dprintf fprintf fscanf fwprintf fwscanf iovfscanf \
                 isoc99_wscanf isoc99_fwscanf isoc99_swscanf \
                 isoc99_vwscanf isoc99_vfwscanf isoc99_vswscanf \
                 nextup nextdown totalorder totalordermag getpayload \
-                canonicalize
+                canonicalize setpayload
 libnldbl-routines = $(libnldbl-calls:%=nldbl-%)
 libnldbl-inhibit-o = $(object-suffixes)
 libnldbl-static-only-routines = $(libnldbl-routines)
@@ -138,6 +138,7 @@ CFLAGS-nldbl-round.c = -fno-builtin-roundl
 CFLAGS-nldbl-scalb.c = -fno-builtin-scalbl
 CFLAGS-nldbl-scalbln.c = -fno-builtin-scalblnl
 CFLAGS-nldbl-scalbn.c = -fno-builtin-scalbnl
+CFLAGS-nldbl-setpayload.c = -fno-builtin-setpayloadl
 CFLAGS-nldbl-significand.c = -fno-builtin-significandl
 CFLAGS-nldbl-sin.c = -fno-builtin-sinl
 CFLAGS-nldbl-sincos.c = -fno-builtin-sincosl
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c b/sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c
new file mode 100644 (file)
index 0000000..2336b99
--- /dev/null
@@ -0,0 +1,26 @@
+/* Compatibility routine for IEEE double as long double for setpayload.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include "nldbl-compat.h"
+
+int
+attribute_hidden
+setpayloadl (double *x, double payload)
+{
+  return setpayload (x, payload);
+}
index b0fc19f9f74668bb8eba0732056f4a53bc49874c..f6f45d3010a19285b2e7fa215d24867184630414 100644 (file)
@@ -392,6 +392,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 9d5936c5c6d6be82101c1f3628e61439d0106125..4d94f5b2d1141912576075f55e4264650cd99c55 100644 (file)
@@ -424,6 +424,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index ce5be3c567eb4dd6d3811150dc1355d078241f6d..0eea474d795a1db360218703d99c01230ba5f5a8 100644 (file)
@@ -434,6 +434,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 675dfa5b865049569376ea46e0d8c6d9cb44b9ec..26d2b2130f21f3ba989417f913cb38eebea1e840 100644 (file)
@@ -81,6 +81,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 75b71ad8f7f2aaa0a2b9479b3c68a50c827f8746..d081d7b3e088646dbd74c633f989418d5b22e1ee 100644 (file)
@@ -393,6 +393,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 5db3def6fdba86174898c2173d7d002927fab110..cc8be123cea32c8ee09245e6ec3e98f23e72208c 100644 (file)
@@ -437,6 +437,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index a80c93a00fc8d95148fa6644df459688f08f7c7a..1aa546868c832a800f387922804280b36b95ace1 100644 (file)
@@ -366,6 +366,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 675dfa5b865049569376ea46e0d8c6d9cb44b9ec..26d2b2130f21f3ba989417f913cb38eebea1e840 100644 (file)
@@ -81,6 +81,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index c795dbdc88612a8f62972450340bf6390f04df2f..6ffebfddf7cf28e89dd83d57a657d3e84db2d1bd 100644 (file)
@@ -435,6 +435,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index cdc8f19971ebc7eee1ecb51127407cf927765bae..9752f2f5189fa445465e6063156b305983c6dbaa 100644 (file)
@@ -392,6 +392,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index a610b03eba1b2e9c493b96289681a36e3d2c8313..edde2f29fe0e55fcb649c7c9090aa56fda7cb36e 100644 (file)
@@ -394,6 +394,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index dfd888cf7062dad86de4a451979fb6c3bcbafa8f..67705e84a3beed35a2ba6b53469a81fc4597610c 100644 (file)
@@ -426,6 +426,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index a6c505d19a94a873ede646686b77c206c6fa979d..86f75cb60dfb340140ac88ac9e725846a614200d 100644 (file)
@@ -392,6 +392,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 9a5f983c3c716cad17ebd136373253a3a248832b..6bd32bb301a9612ada113276af814a5ef50db02b 100644 (file)
@@ -437,6 +437,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 24f0127055a1e7e95248320b71cfe4434b784a46..2ae95e2fe09d8117a433ff98272ebc53e9b24e12 100644 (file)
@@ -436,6 +436,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 00c7d22dfc798cdbcaee8bc560d9f950a7107b5d..35fd922895cb6a4320738a4fd6a5f26082859e30 100644 (file)
@@ -431,6 +431,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index bfbaa366341f6a5ff6cffb9da80eb10e350565e1..d61629201d47d297dde14cf54ed1ef0cf8d34624 100644 (file)
@@ -112,6 +112,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 6e52936a88ad47d3ab50a19e9e14a9060ba16cff..f3310692e8f4cf86ffe52999e73bea2654ace612 100644 (file)
@@ -424,6 +424,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index a01c58857bedd706f0d58d0e853c7fd07051114d..e105c77e0df5320f3090c26f295ae074125de41c 100644 (file)
@@ -422,6 +422,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 96497844bb48a512c623e40063d3cb82023d6c4e..4c24c90a60610901a39f7163cec36e3154a2980c 100644 (file)
@@ -393,6 +393,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index ba109339197a9afce145bdcda91c2e47e2a2f9ba..dbf19bd74ffdbdfb1665e63c578283b32ff1be94 100644 (file)
@@ -427,6 +427,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 82245edfba5b848ce3cd82bcf5e3ff00e6902ab8..83e8308b1fb4a209a5a2020a24924735d444d2af 100644 (file)
@@ -425,6 +425,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 1d4d6f98c682ef676cc6112ea0d8ad2905969573..7306e4699572efccbf14576a98a5d0cb0874f7f1 100644 (file)
@@ -393,6 +393,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 1d4d6f98c682ef676cc6112ea0d8ad2905969573..7306e4699572efccbf14576a98a5d0cb0874f7f1 100644 (file)
@@ -393,6 +393,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 1d4d6f98c682ef676cc6112ea0d8ad2905969573..7306e4699572efccbf14576a98a5d0cb0874f7f1 100644 (file)
@@ -393,6 +393,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index b0bbadac0913fd7f899587a6cffee5292bfa8de4..cabd7fe78fe94bfa5ae1348a09deb3911bcde8a1 100644 (file)
@@ -426,6 +426,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F
index 87f085202fedf0ec35814143fafabd38cfc1bb77..ff64e99bb1584bdfe5ecc5c7f9985d2267030760 100644 (file)
@@ -425,6 +425,9 @@ GLIBC_2.25 fetestexceptflag F
 GLIBC_2.25 getpayload F
 GLIBC_2.25 getpayloadf F
 GLIBC_2.25 getpayloadl F
+GLIBC_2.25 setpayload F
+GLIBC_2.25 setpayloadf F
+GLIBC_2.25 setpayloadl F
 GLIBC_2.25 totalorder F
 GLIBC_2.25 totalorderf F
 GLIBC_2.25 totalorderl F