maint: update copyright
[gnulib.git] / tests / test-copysignl.c
1 /* Test of copysignl() function.
2    Copyright (C) 2010-2014 Free Software Foundation, Inc.
3
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.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010-2011.  */
18
19 #include <config.h>
20
21 #include <math.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (copysignl, long double, (long double, long double));
25
26 #include "macros.h"
27 #include "minus-zero.h"
28
29 #include <string.h>
30
31 volatile long double x;
32 volatile long double y;
33 long double z;
34 long double zero = 0.0L;
35
36 int
37 main ()
38 {
39   /* A particular value in the first quadrant.  */
40   x = 0.6L;
41   y = 0.8L;
42   z = copysignl (x, y);
43   ASSERT (z == 0.6L);
44
45   /* A particular value in the second quadrant.  */
46   x = -0.6L;
47   y = 0.8L;
48   z = copysignl (x, y);
49   ASSERT (z == 0.6L);
50
51   /* A particular value in the third quadrant.  */
52   x = -0.6L;
53   y = -0.8L;
54   z = copysignl (x, y);
55   ASSERT (z == -0.6L);
56
57   /* A particular value in the fourth quadrant.  */
58   x = 0.6L;
59   y = -0.8L;
60   z = copysignl (x, y);
61   ASSERT (z == -0.6L);
62
63   /* From signed zero.  */
64   x = 1.0L;
65   y = 0.0L;
66   z = copysignl (x, y);
67   ASSERT (z == 1.0L);
68
69   x = 1.0L;
70   y = minus_zerol;
71   z = copysignl (x, y);
72   /* Assume all gnulib targets support -0.0L, until proven otherwise.  */
73   ASSERT (z == -1.0L);
74
75   x = -1.0L;
76   y = 0.0L;
77   z = copysignl (x, y);
78   ASSERT (z == 1.0L);
79
80   x = -1.0L;
81   y = minus_zerol;
82   z = copysignl (x, y);
83   ASSERT (z == -1.0L);
84
85   /* To signed zero.  */
86   x = 0.0L;
87   y = 1.0L;
88   z = copysignl (x, y);
89   ASSERT (z == 0.0L);
90   ASSERT (memcmp (&z, &zero, sizeof z) == 0);
91
92   x = 0.0L;
93   y = -1.0L;
94   z = copysignl (x, y);
95   ASSERT (z == 0.0L);
96   ASSERT (memcmp (&z, &zero, sizeof z) != 0);
97
98   x = minus_zerol;
99   y = 1.0L;
100   z = copysignl (x, y);
101   ASSERT (z == 0.0L);
102   ASSERT (memcmp (&z, &zero, sizeof z) == 0);
103
104   x = minus_zerol;
105   y = -1.0L;
106   z = copysignl (x, y);
107   ASSERT (z == 0.0L);
108   ASSERT (memcmp (&z, &zero, sizeof z) != 0);
109
110   return 0;
111 }