annotate tests/test-round1.c @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
1 /* Test of rounding to nearest, breaking ties away from zero.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
3
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9646
diff changeset
6 the Free Software Foundation; either version 3, or (at your option)
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
7 any later version.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
8
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
12 GNU General Public License for more details.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
13
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
16
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
17 /* Written by Ben Pfaff <blp@gnu.org>, 2007.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
18 Based heavily on Bruno Haible's test-trunc.c. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
19
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
20 #include <config.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
21
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
22 #include <math.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
23
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25 SIGNATURE_CHECK (round, double, (double));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
26
10264
ebb7ea0c94e8 Rename isnand.h to isnand-nolibm.h, similarly for isnanf.h.
Ben Pfaff <blp@cs.stanford.edu>
parents: 9889
diff changeset
27 #include "isnand-nolibm.h"
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
28 #include "minus-zero.h"
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
29 #include "infinity.h"
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
30 #include "nan.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
31 #include "macros.h"
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
32
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
33 int
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
34 main ()
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
35 {
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
36 /* Zero. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
37 ASSERT (round (0.0) == 0.0);
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
38 ASSERT (round (minus_zerod) == 0.0);
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
39 /* Positive numbers. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
40 ASSERT (round (0.3) == 0.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
41 ASSERT (round (0.5) == 1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
42 ASSERT (round (0.7) == 1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
43 ASSERT (round (1.0) == 1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
44 ASSERT (round (1.5) == 2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
45 ASSERT (round (2.5) == 3.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
46 ASSERT (round (1.999) == 2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
47 ASSERT (round (2.0) == 2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
48 ASSERT (round (65535.999) == 65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
49 ASSERT (round (65536.0) == 65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
50 ASSERT (round (65536.001) == 65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
51 ASSERT (round (2.341e31) == 2.341e31);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
52 /* Negative numbers. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
53 ASSERT (round (-0.3) == 0.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
54 ASSERT (round (-0.5) == -1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
55 ASSERT (round (-0.7) == -1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
56 ASSERT (round (-1.0) == -1.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
57 ASSERT (round (-1.5) == -2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
58 ASSERT (round (-2.5) == -3.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
59 ASSERT (round (-1.999) == -2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
60 ASSERT (round (-2.0) == -2.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
61 ASSERT (round (-65535.999) == -65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
62 ASSERT (round (-65536.0) == -65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
63 ASSERT (round (-65536.001) == -65536.0);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
64 ASSERT (round (-2.341e31) == -2.341e31);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
65 /* Infinite numbers. */
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
66 ASSERT (round (Infinityd ()) == Infinityd ());
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
67 ASSERT (round (- Infinityd ()) == - Infinityd ());
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
68 /* NaNs. */
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
69 ASSERT (isnand (round (NaNd ())));
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
70
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
71 return 0;
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
72 }