openat: don’t close (-1)
[gnulib.git] / tests / test-setpayloadf.c
blob7d741085178f6aee86379b577b44810f772b19c7
1 /* Test setpayloadf.
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 (setpayloadf, 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 = setpayloadf (&x, p);
45 ASSERT (ret == 0);
46 ASSERT (isnanf (x));
48 /* Test out-of-range payload. */
49 int ret;
50 float x;
52 ret = setpayloadf (&x, p);
53 ASSERT (ret != 0);
54 ASSERT (x == 0.0f);
57 /* Test infinite payload. */
59 int ret;
60 float x;
62 ret = setpayloadf (&x, Infinityf ());
63 ASSERT (ret != 0);
64 ASSERT (x == 0.0f);
67 /* Test negative payload. */
69 int ret;
70 float x;
72 ret = setpayloadf (&x, -1.0f);
73 ASSERT (ret != 0);
74 ASSERT (x == 0.0f);
77 /* Test fractional payload. */
79 int ret;
80 float x;
82 ret = setpayloadf (&x, 1.4f);
83 ASSERT (ret != 0);
84 ASSERT (x == 0.0f);
87 return test_exit_status;