Mercurial > gnulib
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 |
rev | line source |
---|---|
12805 | 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 | 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 | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
12805 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <math.h> | |
22 | |
23 #include "signature.h" | |
24 SIGNATURE_CHECK (rint, double, (double)); | |
25 | |
15916 | 26 #include <float.h> |
27 #include <stdio.h> | |
12805 | 28 |
15916 | 29 #include "isnand-nolibm.h" |
30 #include "minus-zero.h" | |
31 #include "infinity.h" | |
32 #include "nan.h" | |
33 #include "macros.h" | |
12805 | 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 | 38 #define DOUBLE double |
39 #define ISNAN isnand | |
40 #define INFINITY Infinityd () | |
41 #define NAN NaNd () | |
42 #define L_(literal) literal | |
43 #define RINT rint | |
44 #define RANDOM randomd | |
45 #include "test-rint.h" | |
46 | |
12805 | 47 int |
48 main () | |
49 { | |
15916 | 50 /* Consider the current rounding mode, cf. |
51 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html> */ | |
52 if (FLT_ROUNDS == 1) | |
53 { | |
54 /* The current rounding mode is round-to-nearest | |
55 (the default in IEEE 754). */ | |
12805 | 56 |
15916 | 57 /* Zero. */ |
58 ASSERT (rint (0.0) == 0.0); | |
59 ASSERT (rint (minus_zerod) == 0.0); | |
60 /* Positive numbers. */ | |
61 ASSERT (rint (0.3) == 0.0); | |
62 ASSERT (rint (0.5) == 0.0); /* unlike round() */ | |
63 ASSERT (rint (0.7) == 1.0); | |
64 ASSERT (rint (1.0) == 1.0); | |
65 ASSERT (rint (1.5) == 2.0); | |
66 ASSERT (rint (1.999) == 2.0); | |
67 ASSERT (rint (2.0) == 2.0); | |
68 ASSERT (rint (2.1) == 2.0); | |
69 ASSERT (rint (2.5) == 2.0); /* unlike round() */ | |
70 ASSERT (rint (2.7) == 3.0); | |
71 ASSERT (rint (65535.999) == 65536.0); | |
72 ASSERT (rint (65536.0) == 65536.0); | |
73 ASSERT (rint (65536.001) == 65536.0); | |
74 ASSERT (rint (2.341e31) == 2.341e31); | |
75 /* Negative numbers. */ | |
76 ASSERT (rint (-0.3) == 0.0); | |
77 ASSERT (rint (-0.5) == 0.0); /* unlike round() */ | |
78 ASSERT (rint (-0.7) == -1.0); | |
79 ASSERT (rint (-1.0) == -1.0); | |
80 ASSERT (rint (-1.5) == -2.0); | |
81 ASSERT (rint (-1.999) == -2.0); | |
82 ASSERT (rint (-2.0) == -2.0); | |
83 ASSERT (rint (-2.1) == -2.0); | |
84 ASSERT (rint (-2.5) == -2.0); /* unlike round() */ | |
85 ASSERT (rint (-2.7) == -3.0); | |
86 ASSERT (rint (-65535.999) == -65536.0); | |
87 ASSERT (rint (-65536.0) == -65536.0); | |
88 ASSERT (rint (-65536.001) == -65536.0); | |
89 ASSERT (rint (-2.341e31) == -2.341e31); | |
16563 | 90 |
91 test_function (); | |
12805 | 92 |
15916 | 93 return 0; |
94 } | |
95 else | |
96 { | |
97 fputs ("Skipping test: non-standard rounding mode\n", stderr); | |
98 return 77; | |
99 } | |
12805 | 100 } |