Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: gcc/mpfr/tests/tfits.c

Issue 3050029: [gcc] GCC 4.5.0=>4.5.1 (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/nacl-toolchain.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gcc/mpfr/tests/tfactorial.c ('k') | gcc/mpfr/tests/tfms.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Test file for:
2 mpfr_fits_sint_p, mpfr_fits_slong_p, mpfr_fits_sshort_p,
3 mpfr_fits_uint_p, mpfr_fits_ulong_p, mpfr_fits_ushort_p
4
5 Copyright 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 Contributed by the Arenaire and Cacao projects, INRIA.
7
8 This file is part of the GNU MPFR Library.
9
10 The GNU MPFR Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or (at your
13 option) any later version.
14
15 The GNU MPFR Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with the GNU MPFR Library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 MA 02110-1301, USA. */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h" /* for a build within gmp */
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <limits.h>
32
33 /* The ISO C99 standard specifies that in C++ implementations the
34 INTMAX_MAX, ... macros should only be defined if explicitly requested. */
35 #if defined __cplusplus
36 # define __STDC_LIMIT_MACROS
37 # define __STDC_CONSTANT_MACROS
38 #endif
39
40 #if HAVE_INTTYPES_H
41 # include <inttypes.h> /* for intmax_t */
42 #else
43 # if HAVE_STDINT_H
44 # include <stdint.h>
45 # endif
46 #endif
47
48 #include "mpfr-test.h"
49
50 #define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
51 #define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
52
53 static void check_intmax (void);
54
55 int
56 main (void)
57 {
58 mpfr_t x;
59
60 tests_start_mpfr ();
61
62 mpfr_init2 (x, 256);
63
64 /* Check NAN */
65 mpfr_set_nan(x);
66 if (mpfr_fits_ulong_p(x, GMP_RNDN))
67 ERROR1;
68 if (mpfr_fits_slong_p(x, GMP_RNDN))
69 ERROR1;
70 if (mpfr_fits_uint_p(x, GMP_RNDN))
71 ERROR1;
72 if (mpfr_fits_sint_p(x, GMP_RNDN))
73 ERROR1;
74 if (mpfr_fits_ushort_p(x, GMP_RNDN))
75 ERROR1;
76 if (mpfr_fits_sshort_p(x, GMP_RNDN))
77 ERROR1;
78
79 /* Check INF */
80 mpfr_set_inf(x, 1);
81 if (mpfr_fits_ulong_p(x, GMP_RNDN))
82 ERROR1;
83 if (mpfr_fits_slong_p(x, GMP_RNDN))
84 ERROR1;
85 if (mpfr_fits_uint_p(x, GMP_RNDN))
86 ERROR1;
87 if (mpfr_fits_sint_p(x, GMP_RNDN))
88 ERROR1;
89 if (mpfr_fits_ushort_p(x, GMP_RNDN))
90 ERROR1;
91 if (mpfr_fits_sshort_p(x, GMP_RNDN))
92 ERROR1;
93
94 /* Check Zero */
95 MPFR_SET_ZERO(x);
96 if (!mpfr_fits_ulong_p(x, GMP_RNDN))
97 ERROR2;
98 if (!mpfr_fits_slong_p(x, GMP_RNDN))
99 ERROR2;
100 if (!mpfr_fits_uint_p(x, GMP_RNDN))
101 ERROR2;
102 if (!mpfr_fits_sint_p(x, GMP_RNDN))
103 ERROR2;
104 if (!mpfr_fits_ushort_p(x, GMP_RNDN))
105 ERROR2;
106 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
107 ERROR2;
108
109 /* Check small op */
110 mpfr_set_str1 (x, "1@-1");
111 if (!mpfr_fits_ulong_p(x, GMP_RNDN))
112 ERROR2;
113 if (!mpfr_fits_slong_p(x, GMP_RNDN))
114 ERROR2;
115 if (!mpfr_fits_uint_p(x, GMP_RNDN))
116 ERROR2;
117 if (!mpfr_fits_sint_p(x, GMP_RNDN))
118 ERROR2;
119 if (!mpfr_fits_ushort_p(x, GMP_RNDN))
120 ERROR2;
121 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
122 ERROR2;
123
124 /* Check 17 */
125 mpfr_set_ui (x, 17, GMP_RNDN);
126 if (!mpfr_fits_ulong_p(x, GMP_RNDN))
127 ERROR2;
128 if (!mpfr_fits_slong_p(x, GMP_RNDN))
129 ERROR2;
130 if (!mpfr_fits_uint_p(x, GMP_RNDN))
131 ERROR2;
132 if (!mpfr_fits_sint_p(x, GMP_RNDN))
133 ERROR2;
134 if (!mpfr_fits_ushort_p(x, GMP_RNDN))
135 ERROR2;
136 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
137 ERROR2;
138
139 /* Check all other values */
140 mpfr_set_ui(x, ULONG_MAX, GMP_RNDN);
141 mpfr_mul_2exp(x, x, 1, GMP_RNDN);
142 if (mpfr_fits_ulong_p(x, GMP_RNDN))
143 ERROR1;
144 if (mpfr_fits_slong_p(x, GMP_RNDN))
145 ERROR1;
146 mpfr_mul_2exp(x, x, 40, GMP_RNDN);
147 if (mpfr_fits_ulong_p(x, GMP_RNDN))
148 ERROR1;
149 if (mpfr_fits_uint_p(x, GMP_RNDN))
150 ERROR1;
151 if (mpfr_fits_sint_p(x, GMP_RNDN))
152 ERROR1;
153 if (mpfr_fits_ushort_p(x, GMP_RNDN))
154 ERROR1;
155 if (mpfr_fits_sshort_p(x, GMP_RNDN))
156 ERROR1;
157
158 mpfr_set_ui(x, ULONG_MAX, GMP_RNDN);
159 if (!mpfr_fits_ulong_p(x, GMP_RNDN))
160 ERROR2;
161 mpfr_set_ui(x, LONG_MAX, GMP_RNDN);
162 if (!mpfr_fits_slong_p(x, GMP_RNDN))
163 ERROR2;
164 mpfr_set_ui(x, UINT_MAX, GMP_RNDN);
165 if (!mpfr_fits_uint_p(x, GMP_RNDN))
166 ERROR2;
167 mpfr_set_ui(x, INT_MAX, GMP_RNDN);
168 if (!mpfr_fits_sint_p(x, GMP_RNDN))
169 ERROR2;
170 mpfr_set_ui(x, USHRT_MAX, GMP_RNDN);
171 if (!mpfr_fits_ushort_p(x, GMP_RNDN))
172 ERROR2;
173 mpfr_set_ui(x, SHRT_MAX, GMP_RNDN);
174 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
175 ERROR2;
176
177 mpfr_set_si(x, 1, GMP_RNDN);
178 if (!mpfr_fits_sint_p(x, GMP_RNDN))
179 ERROR2;
180 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
181 ERROR2;
182
183 /* Check negative value */
184 mpfr_set_si (x, -1, GMP_RNDN);
185 if (!mpfr_fits_sint_p(x, GMP_RNDN))
186 ERROR2;
187 if (!mpfr_fits_sshort_p(x, GMP_RNDN))
188 ERROR2;
189 if (!mpfr_fits_slong_p(x, GMP_RNDN))
190 ERROR2;
191 if (mpfr_fits_uint_p(x, GMP_RNDN))
192 ERROR1;
193 if (mpfr_fits_ushort_p(x, GMP_RNDN))
194 ERROR1;
195 if (mpfr_fits_ulong_p(x, GMP_RNDN))
196 ERROR1;
197
198 mpfr_clear (x);
199
200 check_intmax ();
201
202 tests_end_mpfr ();
203 return 0;
204 }
205
206 static void check_intmax (void)
207 {
208 #ifdef _MPFR_H_HAVE_INTMAX_T
209 mpfr_t x;
210
211 mpfr_init2 (x, sizeof(uintmax_t)*CHAR_BIT);
212
213 /* Check NAN */
214 mpfr_set_nan(x);
215 if (mpfr_fits_uintmax_p(x, GMP_RNDN))
216 ERROR1;
217 if (mpfr_fits_intmax_p(x, GMP_RNDN))
218 ERROR1;
219
220 /* Check INF */
221 mpfr_set_inf(x, 1);
222 if (mpfr_fits_uintmax_p(x, GMP_RNDN))
223 ERROR1;
224 if (mpfr_fits_intmax_p(x, GMP_RNDN))
225 ERROR1;
226
227 /* Check Zero */
228 MPFR_SET_ZERO(x);
229 if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
230 ERROR2;
231 if (!mpfr_fits_intmax_p(x, GMP_RNDN))
232 ERROR2;
233
234 /* Check small op */
235 mpfr_set_str1 (x, "1@-1");
236 if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
237 ERROR2;
238 if (!mpfr_fits_intmax_p(x, GMP_RNDN))
239 ERROR2;
240
241 /* Check 17 */
242 mpfr_set_ui (x, 17, GMP_RNDN);
243 if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
244 ERROR2;
245 if (!mpfr_fits_intmax_p(x, GMP_RNDN))
246 ERROR2;
247
248 /* Check hugest */
249 mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, GMP_RNDN);
250 if (mpfr_fits_uintmax_p (x, GMP_RNDN))
251 ERROR1;
252 if (mpfr_fits_intmax_p (x, GMP_RNDN))
253 ERROR1;
254
255 /* Check all other values */
256 mpfr_set_uj (x, UINTMAX_MAX, GMP_RNDN);
257 mpfr_add_ui (x, x, 1, GMP_RNDN);
258 if (mpfr_fits_uintmax_p (x, GMP_RNDN))
259 ERROR1;
260 mpfr_set_uj (x, UINTMAX_MAX, GMP_RNDN);
261 if (!mpfr_fits_uintmax_p (x, GMP_RNDN))
262 ERROR2;
263 mpfr_set_sj (x, INTMAX_MAX, GMP_RNDN);
264 mpfr_add_ui (x, x, 1, GMP_RNDN);
265 if (mpfr_fits_intmax_p (x, GMP_RNDN))
266 ERROR1;
267 mpfr_set_sj (x, INTMAX_MAX, GMP_RNDN);
268 if (!mpfr_fits_intmax_p (x, GMP_RNDN))
269 ERROR2;
270 mpfr_set_sj (x, INTMAX_MIN, GMP_RNDN);
271 if (!mpfr_fits_intmax_p (x, GMP_RNDN))
272 ERROR2;
273 mpfr_sub_ui (x, x, 1, GMP_RNDN);
274 if (mpfr_fits_intmax_p (x, GMP_RNDN))
275 ERROR1;
276
277 /* Check negative value */
278 mpfr_set_si (x, -1, GMP_RNDN);
279 if (!mpfr_fits_intmax_p (x, GMP_RNDN))
280 ERROR2;
281 if (mpfr_fits_uintmax_p (x, GMP_RNDN))
282 ERROR1;
283
284 mpfr_clear (x);
285 #endif
286 }
287
OLDNEW
« no previous file with comments | « gcc/mpfr/tests/tfactorial.c ('k') | gcc/mpfr/tests/tfms.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698