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 Free Software Foundation, Inc.
7
This file is part of the MPFR Library.
9
The MPFR Library is free software; you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation; either version 2.1 of the License, or (at your
12
option) any later version.
14
The MPFR Library is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
License for more details.
19
You should have received a copy of the GNU Lesser General Public License
20
along with the MPFR Library; see the file COPYING.LIB. If not, write to
21
the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
22
MA 02110-1301, USA. */
25
# include "config.h" /* for a build within gmp */
32
/* The ISO C99 standard specifies that in C++ implementations the
33
INTMAX_MAX, ... macros should only be defined if explicitly requested. */
34
#if defined __cplusplus
35
# define __STDC_LIMIT_MACROS
36
# define __STDC_CONSTANT_MACROS
42
#ifdef HAVE_INTTYPES_H
43
# include <inttypes.h>
46
#include "mpfr-test.h"
48
#define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
49
#define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
51
static void check_intmax (void);
64
if (mpfr_fits_ulong_p(x, GMP_RNDN))
66
if (mpfr_fits_slong_p(x, GMP_RNDN))
68
if (mpfr_fits_uint_p(x, GMP_RNDN))
70
if (mpfr_fits_sint_p(x, GMP_RNDN))
72
if (mpfr_fits_ushort_p(x, GMP_RNDN))
74
if (mpfr_fits_sshort_p(x, GMP_RNDN))
79
if (mpfr_fits_ulong_p(x, GMP_RNDN))
81
if (mpfr_fits_slong_p(x, GMP_RNDN))
83
if (mpfr_fits_uint_p(x, GMP_RNDN))
85
if (mpfr_fits_sint_p(x, GMP_RNDN))
87
if (mpfr_fits_ushort_p(x, GMP_RNDN))
89
if (mpfr_fits_sshort_p(x, GMP_RNDN))
94
if (!mpfr_fits_ulong_p(x, GMP_RNDN))
96
if (!mpfr_fits_slong_p(x, GMP_RNDN))
98
if (!mpfr_fits_uint_p(x, GMP_RNDN))
100
if (!mpfr_fits_sint_p(x, GMP_RNDN))
102
if (!mpfr_fits_ushort_p(x, GMP_RNDN))
104
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
108
mpfr_set_str1 (x, "1@-1");
109
if (!mpfr_fits_ulong_p(x, GMP_RNDN))
111
if (!mpfr_fits_slong_p(x, GMP_RNDN))
113
if (!mpfr_fits_uint_p(x, GMP_RNDN))
115
if (!mpfr_fits_sint_p(x, GMP_RNDN))
117
if (!mpfr_fits_ushort_p(x, GMP_RNDN))
119
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
123
mpfr_set_ui (x, 17, GMP_RNDN);
124
if (!mpfr_fits_ulong_p(x, GMP_RNDN))
126
if (!mpfr_fits_slong_p(x, GMP_RNDN))
128
if (!mpfr_fits_uint_p(x, GMP_RNDN))
130
if (!mpfr_fits_sint_p(x, GMP_RNDN))
132
if (!mpfr_fits_ushort_p(x, GMP_RNDN))
134
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
137
/* Check all other values */
138
mpfr_set_ui(x, ULONG_MAX, GMP_RNDN);
139
mpfr_mul_2exp(x, x, 1, GMP_RNDN);
140
if (mpfr_fits_ulong_p(x, GMP_RNDN))
142
if (mpfr_fits_slong_p(x, GMP_RNDN))
144
mpfr_mul_2exp(x, x, 40, GMP_RNDN);
145
if (mpfr_fits_ulong_p(x, GMP_RNDN))
147
if (mpfr_fits_uint_p(x, GMP_RNDN))
149
if (mpfr_fits_sint_p(x, GMP_RNDN))
151
if (mpfr_fits_ushort_p(x, GMP_RNDN))
153
if (mpfr_fits_sshort_p(x, GMP_RNDN))
156
mpfr_set_ui(x, ULONG_MAX, GMP_RNDN);
157
if (!mpfr_fits_ulong_p(x, GMP_RNDN))
159
mpfr_set_ui(x, LONG_MAX, GMP_RNDN);
160
if (!mpfr_fits_slong_p(x, GMP_RNDN))
162
mpfr_set_ui(x, UINT_MAX, GMP_RNDN);
163
if (!mpfr_fits_uint_p(x, GMP_RNDN))
165
mpfr_set_ui(x, INT_MAX, GMP_RNDN);
166
if (!mpfr_fits_sint_p(x, GMP_RNDN))
168
mpfr_set_ui(x, USHRT_MAX, GMP_RNDN);
169
if (!mpfr_fits_ushort_p(x, GMP_RNDN))
171
mpfr_set_ui(x, SHRT_MAX, GMP_RNDN);
172
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
175
mpfr_set_si(x, 1, GMP_RNDN);
176
if (!mpfr_fits_sint_p(x, GMP_RNDN))
178
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
181
/* Check negative value */
182
mpfr_set_si (x, -1, GMP_RNDN);
183
if (!mpfr_fits_sint_p(x, GMP_RNDN))
185
if (!mpfr_fits_sshort_p(x, GMP_RNDN))
187
if (!mpfr_fits_slong_p(x, GMP_RNDN))
189
if (mpfr_fits_uint_p(x, GMP_RNDN))
191
if (mpfr_fits_ushort_p(x, GMP_RNDN))
193
if (mpfr_fits_ulong_p(x, GMP_RNDN))
204
static void check_intmax (void)
206
#ifdef _MPFR_H_HAVE_INTMAX_T
209
mpfr_init2 (x, sizeof(uintmax_t)*CHAR_BIT);
213
if (mpfr_fits_uintmax_p(x, GMP_RNDN))
215
if (mpfr_fits_intmax_p(x, GMP_RNDN))
220
if (mpfr_fits_uintmax_p(x, GMP_RNDN))
222
if (mpfr_fits_intmax_p(x, GMP_RNDN))
227
if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
229
if (!mpfr_fits_intmax_p(x, GMP_RNDN))
233
mpfr_set_str1 (x, "1@-1");
234
if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
236
if (!mpfr_fits_intmax_p(x, GMP_RNDN))
240
mpfr_set_ui (x, 17, GMP_RNDN);
241
if (!mpfr_fits_uintmax_p(x, GMP_RNDN))
243
if (!mpfr_fits_intmax_p(x, GMP_RNDN))
247
mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, GMP_RNDN);
248
if (mpfr_fits_uintmax_p (x, GMP_RNDN))
250
if (mpfr_fits_intmax_p (x, GMP_RNDN))
253
/* Check all other values */
254
mpfr_set_uj (x, UINTMAX_MAX, GMP_RNDN);
255
mpfr_add_ui (x, x, 1, GMP_RNDN);
256
if (mpfr_fits_uintmax_p (x, GMP_RNDN))
258
mpfr_set_uj (x, UINTMAX_MAX, GMP_RNDN);
259
if (!mpfr_fits_uintmax_p (x, GMP_RNDN))
261
mpfr_set_sj (x, INTMAX_MAX, GMP_RNDN);
262
mpfr_add_ui (x, x, 1, GMP_RNDN);
263
if (mpfr_fits_intmax_p (x, GMP_RNDN))
265
mpfr_set_sj (x, INTMAX_MAX, GMP_RNDN);
266
if (!mpfr_fits_intmax_p (x, GMP_RNDN))
268
mpfr_set_sj (x, INTMAX_MIN, GMP_RNDN);
269
if (!mpfr_fits_intmax_p (x, GMP_RNDN))
271
mpfr_sub_ui (x, x, 1, GMP_RNDN);
272
if (mpfr_fits_intmax_p (x, GMP_RNDN))
275
/* Check negative value */
276
mpfr_set_si (x, -1, GMP_RNDN);
277
if (!mpfr_fits_intmax_p (x, GMP_RNDN))
279
if (mpfr_fits_uintmax_p (x, GMP_RNDN))