annotate tests/test-copysign.c @ 14079:97fc9a21a8fb

maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
author Jim Meyering <meyering@redhat.com>
date Sat, 01 Jan 2011 20:17:23 +0100
parents 2ba13be8e841
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12783
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of copysign() function.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 13836
diff changeset
2 Copyright (C) 2010-2011 Free Software Foundation, Inc.
12783
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "signature.h"
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 SIGNATURE_CHECK (copysign, double, (double, double));
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "macros.h"
13836
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
27 #include "minus-zero.h"
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
28
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
29 #include <string.h>
12783
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 volatile double x;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 volatile double y;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 double z;
13836
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
34 double zero = 0.0;
12783
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 int
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 main ()
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 {
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 /* A particular value in the first quadrant. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 x = 0.6;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 y = 0.8;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 z = copysign (x, y);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 ASSERT (z == 0.6);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 /* A particular value in the second quadrant. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 x = -0.6;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 y = 0.8;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 z = copysign (x, y);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ASSERT (z == 0.6);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* A particular value in the third quadrant. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 x = -0.6;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 y = -0.8;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 z = copysign (x, y);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 ASSERT (z == -0.6);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 /* A particular value in the fourth quadrant. */
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 x = 0.6;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 y = -0.8;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 z = copysign (x, y);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ASSERT (z == -0.6);
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
13836
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
63 /* From signed zero. */
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
64 x = 1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
65 y = 0.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
66 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
67 ASSERT (z == 1.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
68
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
69 x = 1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
70 y = minus_zerod;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
71 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
72 /* Assume all gnulib targets support -0.0, until proven otherwise. */
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
73 ASSERT (z == -1.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
74
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
75 x = -1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
76 y = 0.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
77 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
78 ASSERT (z == 1.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
79
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
80 x = -1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
81 y = minus_zerod;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
82 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
83 ASSERT (z == -1.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
84
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
85 /* To signed zero. */
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
86 x = 0.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
87 y = 1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
88 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
89 ASSERT (z == 0.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
90 ASSERT (memcmp (&z, &zero, sizeof z) == 0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
91
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
92 x = 0.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
93 y = -1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
94 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
95 ASSERT (z == 0.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
96 ASSERT (memcmp (&z, &zero, sizeof z) != 0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
97
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
98 x = minus_zerod;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
99 y = 1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
100 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
101 ASSERT (z == 0.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
102 ASSERT (memcmp (&z, &zero, sizeof z) == 0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
103
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
104 x = minus_zerod;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
105 y = -1.0;
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
106 z = copysign (x, y);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
107 ASSERT (z == 0.0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
108 ASSERT (memcmp (&z, &zero, sizeof z) != 0);
2ba13be8e841 copysign: enhance tests
Eric Blake <eblake@redhat.com>
parents: 12783
diff changeset
109
12783
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 return 0;
80a5595e7677 Tests for module 'copysign'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 }