gettext: Sync with gettext 0.23.
[gnulib.git] / tests / test-copysignf.c
blobeb3d29a8720d7c30c7321dfef83c8adfe5a97b8f
1 /* Test of copysignf() function.
2 Copyright (C) 2010-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 /* Written by Bruno Haible <bruno@clisp.org>, 2010-2011. */
19 #include <config.h>
21 #include <math.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (copysignf, float, (float, float));
26 #include "macros.h"
27 #include "minus-zero.h"
29 #include <string.h>
31 volatile float x;
32 volatile float y;
33 float z;
34 float zero = 0.0f;
36 int
37 main ()
39 /* A particular value in the first quadrant. */
40 x = 0.6f;
41 y = 0.8f;
42 z = copysignf (x, y);
43 ASSERT (z == 0.6f);
45 /* A particular value in the second quadrant. */
46 x = -0.6f;
47 y = 0.8f;
48 z = copysignf (x, y);
49 ASSERT (z == 0.6f);
51 /* A particular value in the third quadrant. */
52 x = -0.6f;
53 y = -0.8f;
54 z = copysignf (x, y);
55 ASSERT (z == -0.6f);
57 /* A particular value in the fourth quadrant. */
58 x = 0.6f;
59 y = -0.8f;
60 z = copysignf (x, y);
61 ASSERT (z == -0.6f);
63 /* From signed zero. */
64 x = 1.0f;
65 y = 0.0f;
66 z = copysignf (x, y);
67 ASSERT (z == 1.0f);
69 x = 1.0f;
70 y = minus_zerof;
71 z = copysignf (x, y);
72 /* Assume all gnulib targets support -0.0f, until proven otherwise. */
73 ASSERT (z == -1.0f);
75 x = -1.0f;
76 y = 0.0f;
77 z = copysignf (x, y);
78 ASSERT (z == 1.0f);
80 x = -1.0f;
81 y = minus_zerof;
82 z = copysignf (x, y);
83 ASSERT (z == -1.0f);
85 /* To signed zero. */
86 x = 0.0f;
87 y = 1.0f;
88 z = copysignf (x, y);
89 ASSERT (z == 0.0f);
90 ASSERT (memcmp (&z, &zero, sizeof z) == 0);
92 x = 0.0f;
93 y = -1.0f;
94 z = copysignf (x, y);
95 ASSERT (z == 0.0f);
96 ASSERT (memcmp (&z, &zero, sizeof z) != 0);
98 x = minus_zerof;
99 y = 1.0f;
100 z = copysignf (x, y);
101 ASSERT (z == 0.0f);
102 ASSERT (memcmp (&z, &zero, sizeof z) == 0);
104 x = minus_zerof;
105 y = -1.0f;
106 z = copysignf (x, y);
107 ASSERT (z == 0.0f);
108 ASSERT (memcmp (&z, &zero, sizeof z) != 0);
110 return test_exit_status;