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
5 Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
6 Contributed by the AriC and Caramel projects, INRIA.
8 This file is part of the GNU MPFR Library.
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 3 of the License, or (at your
13 option) any later version.
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.
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.LESSER. If not, see
22 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
26 # include "config.h" /* for a build within gmp */
33 #include "mpfr-intmax.h"
34 #include "mpfr-test.h"
36 #define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
37 #define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
39 static void check_intmax (void);
52 if (mpfr_fits_ulong_p (x, MPFR_RNDN))
54 if (mpfr_fits_slong_p (x, MPFR_RNDN))
56 if (mpfr_fits_uint_p (x, MPFR_RNDN))
58 if (mpfr_fits_sint_p (x, MPFR_RNDN))
60 if (mpfr_fits_ushort_p (x, MPFR_RNDN))
62 if (mpfr_fits_sshort_p (x, MPFR_RNDN))
67 if (mpfr_fits_ulong_p (x, MPFR_RNDN))
69 if (mpfr_fits_slong_p (x, MPFR_RNDN))
71 if (mpfr_fits_uint_p (x, MPFR_RNDN))
73 if (mpfr_fits_sint_p (x, MPFR_RNDN))
75 if (mpfr_fits_ushort_p (x, MPFR_RNDN))
77 if (mpfr_fits_sshort_p (x, MPFR_RNDN))
82 if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
84 if (!mpfr_fits_slong_p (x, MPFR_RNDN))
86 if (!mpfr_fits_uint_p (x, MPFR_RNDN))
88 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
90 if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
92 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
96 mpfr_set_str1 (x, "1@-1");
97 if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
99 if (!mpfr_fits_slong_p (x, MPFR_RNDN))
101 if (!mpfr_fits_uint_p (x, MPFR_RNDN))
103 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
105 if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
107 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
111 mpfr_set_ui (x, 17, MPFR_RNDN);
112 if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
114 if (!mpfr_fits_slong_p (x, MPFR_RNDN))
116 if (!mpfr_fits_uint_p (x, MPFR_RNDN))
118 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
120 if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
122 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
125 /* Check all other values */
126 mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
127 mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
128 if (mpfr_fits_ulong_p (x, MPFR_RNDN))
130 if (mpfr_fits_slong_p (x, MPFR_RNDN))
132 mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
133 if (mpfr_fits_ulong_p (x, MPFR_RNDN))
135 if (mpfr_fits_uint_p (x, MPFR_RNDN))
137 if (mpfr_fits_sint_p (x, MPFR_RNDN))
139 if (mpfr_fits_ushort_p (x, MPFR_RNDN))
141 if (mpfr_fits_sshort_p (x, MPFR_RNDN))
144 mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
145 if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
147 mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
148 if (!mpfr_fits_slong_p (x, MPFR_RNDN))
150 mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
151 if (!mpfr_fits_uint_p (x, MPFR_RNDN))
153 mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
154 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
156 mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
157 if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
159 mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
160 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
163 mpfr_set_si (x, 1, MPFR_RNDN);
164 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
166 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
169 /* Check negative value */
170 mpfr_set_si (x, -1, MPFR_RNDN);
171 if (!mpfr_fits_sint_p (x, MPFR_RNDN))
173 if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
175 if (!mpfr_fits_slong_p (x, MPFR_RNDN))
177 if (mpfr_fits_uint_p (x, MPFR_RNDN))
179 if (mpfr_fits_ushort_p (x, MPFR_RNDN))
181 if (mpfr_fits_ulong_p (x, MPFR_RNDN))
192 static void check_intmax (void)
194 #ifdef _MPFR_H_HAVE_INTMAX_T
197 mpfr_init2 (x, sizeof (uintmax_t)*CHAR_BIT);
201 if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
203 if (mpfr_fits_intmax_p (x, MPFR_RNDN))
208 if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
210 if (mpfr_fits_intmax_p (x, MPFR_RNDN))
215 if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
217 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
221 mpfr_set_str1 (x, "1@-1");
222 if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
224 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
228 mpfr_set_ui (x, 17, MPFR_RNDN);
229 if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
231 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
235 mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
236 if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
238 if (mpfr_fits_intmax_p (x, MPFR_RNDN))
241 /* Check all other values */
242 mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
243 mpfr_add_ui (x, x, 1, MPFR_RNDN);
244 if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
246 mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
247 if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
249 mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
250 mpfr_add_ui (x, x, 1, MPFR_RNDN);
251 if (mpfr_fits_intmax_p (x, MPFR_RNDN))
253 mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
254 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
256 mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
257 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
259 mpfr_sub_ui (x, x, 1, MPFR_RNDN);
260 if (mpfr_fits_intmax_p (x, MPFR_RNDN))
263 /* Check negative value */
264 mpfr_set_si (x, -1, MPFR_RNDN);
265 if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
267 if (mpfr_fits_uintmax_p (x, MPFR_RNDN))