maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-setpayloadsigf.c
blob72915b91324723436326279d088f83f7793c89c5
1 /* Test setpayloadsigf.
2 Copyright 2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <math.h>
22 #include "signature.h"
23 SIGNATURE_CHECK (setpayloadsigf, int, (float *, float));
25 #include "infinity.h"
26 #include "isnanf-nolibm.h"
27 #include "macros.h"
29 #define PAYLOAD_BITS (24 - 2) /* = (FLT_MANT_DIG - 2) */
31 int
32 main ()
34 int i;
35 float p;
38 /* Test valid payloads. */
39 for (i = 0, p = 1.0f; i < PAYLOAD_BITS; i++, p *= 2.0f)
41 int ret;
42 float x;
44 ret = setpayloadsigf (&x, p);
45 ASSERT (ret == 0);
46 ASSERT (isnanf (x));
48 /* Test out-of-range payload. */
49 int ret;
50 float x;
52 ret = setpayloadsigf (&x, p);
53 ASSERT (ret != 0);
54 ASSERT (x == 0.0f);
57 /* Test infinite payload. */
59 int ret;
60 float x;
62 ret = setpayloadsigf (&x, Infinityf ());
63 ASSERT (ret != 0);
64 ASSERT (x == 0.0f);
67 /* Test negative payload. */
69 int ret;
70 float x;
72 ret = setpayloadsigf (&x, -1.0f);
73 ASSERT (ret != 0);
74 ASSERT (x == 0.0f);
77 /* Test fractional payload. */
79 int ret;
80 float x;
82 ret = setpayloadsigf (&x, 1.4f);
83 ASSERT (ret != 0);
84 ASSERT (x == 0.0f);
87 return test_exit_status;