annotate tests/test-rint.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
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of rint() function.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2010-2019 Free Software Foundation, Inc.
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
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/>. */
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "signature.h"
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 SIGNATURE_CHECK (rint, double, (double));
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
15916
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
26 #include <float.h>
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
27 #include <stdio.h>
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
15916
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
29 #include "isnand-nolibm.h"
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
30 #include "minus-zero.h"
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
31 #include "infinity.h"
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
32 #include "nan.h"
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
33 #include "macros.h"
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
16797
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
35 #undef INFINITY
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
36 #undef NAN
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
37
16563
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
38 #define DOUBLE double
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39 #define ISNAN isnand
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
40 #define INFINITY Infinityd ()
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
41 #define NAN NaNd ()
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
42 #define L_(literal) literal
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
43 #define RINT rint
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
44 #define RANDOM randomd
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
45 #include "test-rint.h"
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
46
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 int
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 main ()
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
15916
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
50 /* Consider the current rounding mode, cf.
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
51 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html> */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
52 if (FLT_ROUNDS == 1)
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
53 {
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
54 /* The current rounding mode is round-to-nearest
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
55 (the default in IEEE 754). */
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
15916
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
57 /* Zero. */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
58 ASSERT (rint (0.0) == 0.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
59 ASSERT (rint (minus_zerod) == 0.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
60 /* Positive numbers. */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
61 ASSERT (rint (0.3) == 0.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
62 ASSERT (rint (0.5) == 0.0); /* unlike round() */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
63 ASSERT (rint (0.7) == 1.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
64 ASSERT (rint (1.0) == 1.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
65 ASSERT (rint (1.5) == 2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
66 ASSERT (rint (1.999) == 2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
67 ASSERT (rint (2.0) == 2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
68 ASSERT (rint (2.1) == 2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
69 ASSERT (rint (2.5) == 2.0); /* unlike round() */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
70 ASSERT (rint (2.7) == 3.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
71 ASSERT (rint (65535.999) == 65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
72 ASSERT (rint (65536.0) == 65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
73 ASSERT (rint (65536.001) == 65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
74 ASSERT (rint (2.341e31) == 2.341e31);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
75 /* Negative numbers. */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
76 ASSERT (rint (-0.3) == 0.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
77 ASSERT (rint (-0.5) == 0.0); /* unlike round() */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
78 ASSERT (rint (-0.7) == -1.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
79 ASSERT (rint (-1.0) == -1.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
80 ASSERT (rint (-1.5) == -2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
81 ASSERT (rint (-1.999) == -2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
82 ASSERT (rint (-2.0) == -2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
83 ASSERT (rint (-2.1) == -2.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
84 ASSERT (rint (-2.5) == -2.0); /* unlike round() */
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
85 ASSERT (rint (-2.7) == -3.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
86 ASSERT (rint (-65535.999) == -65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
87 ASSERT (rint (-65536.0) == -65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
88 ASSERT (rint (-65536.001) == -65536.0);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
89 ASSERT (rint (-2.341e31) == -2.341e31);
16563
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
90
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
91 test_function ();
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
15916
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
93 return 0;
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
94 }
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
95 else
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
96 {
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
97 fputs ("Skipping test: non-standard rounding mode\n", stderr);
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
98 return 77;
fde577ac9f53 rint tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
99 }
12805
1a4bc6df3018 Tests for module 'rint'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }