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