annotate tests/test-rintl.c @ 17460:d11431703671

autoupdate
author Karl Berry <karl@freefriends.org>
date Fri, 09 Aug 2013 08:03:30 -0700
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15921
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of rintl() function.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16797
diff changeset
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
15921
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "signature.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 SIGNATURE_CHECK (rintl, long double, (long double));
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <float.h>
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdio.h>
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "fpucw.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include "isnanl-nolibm.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include "minus-zero.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include "infinity.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include "nan.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include "macros.h"
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
16797
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
36 #undef INFINITY
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
37 #undef NAN
c4a7dd5a1c2c rint* tests: Avoid gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 16563
diff changeset
38
16563
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39 #define DOUBLE long double
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
40 #define ISNAN isnanl
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
41 #define INFINITY Infinityl ()
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
42 #define NAN NaNl ()
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
43 #define L_(literal) literal##L
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
44 #define RINT rintl
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
45 #define RANDOM randoml
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
46 #include "test-rint.h"
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
47
15921
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 int
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 main ()
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 DECL_LONG_DOUBLE_ROUNDING
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 BEGIN_LONG_DOUBLE_ROUNDING ();
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* Consider the current rounding mode, cf.
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html> */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 if (FLT_ROUNDS == 1)
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 /* The current rounding mode is round-to-nearest
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 (the default in IEEE 754). */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* Zero. */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 ASSERT (rintl (0.0L) == 0.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 ASSERT (rintl (minus_zerol) == 0.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Positive numbers. */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 ASSERT (rintl (0.3L) == 0.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 ASSERT (rintl (0.5L) == 0.0L); /* unlike roundl() */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 ASSERT (rintl (0.7L) == 1.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ASSERT (rintl (1.0L) == 1.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 ASSERT (rintl (1.5L) == 2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 ASSERT (rintl (1.999L) == 2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 ASSERT (rintl (2.0L) == 2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 ASSERT (rintl (2.1L) == 2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 ASSERT (rintl (2.5L) == 2.0L); /* unlike roundl() */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 ASSERT (rintl (2.7L) == 3.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 ASSERT (rintl (65535.999L) == 65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ASSERT (rintl (65536.0L) == 65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ASSERT (rintl (65536.001L) == 65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 ASSERT (rintl (2.341e31L) == 2.341e31L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 /* Negative numbers. */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (rintl (-0.3L) == 0.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (rintl (-0.5L) == 0.0L); /* unlike roundl() */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 ASSERT (rintl (-0.7L) == -1.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (rintl (-1.0L) == -1.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (rintl (-1.5L) == -2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (rintl (-1.999L) == -2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (rintl (-2.0L) == -2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (rintl (-2.1L) == -2.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (rintl (-2.5L) == -2.0L); /* unlike roundl() */
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (rintl (-2.7L) == -3.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (rintl (-65535.999L) == -65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ASSERT (rintl (-65536.0L) == -65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (rintl (-65536.001L) == -65536.0L);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 ASSERT (rintl (-2.341e31L) == -2.341e31L);
16563
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
95
446b5d1c7986 rint* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
96 test_function ();
15921
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 return 0;
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 }
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 else
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 {
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 fputs ("Skipping test: non-standard rounding mode\n", stderr);
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 return 77;
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 }
1f40ef54f475 Tests for module 'rintl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 }