22 #ifndef __GMPFR_GMP_H__
23 #define __GMPFR_GMP_H__
25 #ifndef __MPFR_IMPL_H__
26 # error "mpfr-impl.h not included"
35 # if defined ( __GNUC__ )
36 # define alloca __builtin_alloca
37 # elif defined (__DECC)
38 # define alloca(x) __ALLOCA(x)
39 # elif defined (_MSC_VER)
41 # define alloca _alloca
42 # elif defined (FEELPP_HAS_ALLOCA_H)
44 # elif defined (_AIX) || defined (_IBMR2)
51 #if defined (__cplusplus)
57 #if defined(GMP_NUMB_BITS)
58 # define BITS_PER_MP_LIMB (GMP_NUMB_BITS+GMP_NAIL_BITS)
59 #elif defined (__GMP_BITS_PER_MP_LIMB)
60 # define BITS_PER_MP_LIMB __GMP_BITS_PER_MP_LIMB
61 # define GMP_NUMB_BITS BITS_PER_MP_LIMB
62 # ifndef GMP_NAIL_BITS
63 # define GMP_NAIL_BITS 0
66 # error "Could not detect BITS_PER_MP_LIMB. Try with gmp internal files."
70 #define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB/CHAR_BIT)
72 #define MP_LIMB_T_MAX (~(mp_limb_t)0)
74 #define ULONG_HIGHBIT (ULONG_MAX ^ ((unsigned long) ULONG_MAX >> 1))
75 #define UINT_HIGHBIT (UINT_MAX ^ ((unsigned) UINT_MAX >> 1))
76 #define USHRT_HIGHBIT ((unsigned short) (USHRT_MAX ^ ((unsigned short) USHRT_MAX >> 1)))
78 #define GMP_LIMB_HIGHBIT (MP_LIMB_T_MAX ^ (MP_LIMB_T_MAX >> 1))
81 #if __GMP_MP_SIZE_T_INT
82 #define MP_SIZE_T_MAX INT_MAX
83 #define MP_SIZE_T_MIN INT_MIN
85 #define MP_SIZE_T_MAX LONG_MAX
86 #define MP_SIZE_T_MIN LONG_MIN
89 #define LONG_HIGHBIT LONG_MIN
90 #define INT_HIGHBIT INT_MIN
91 #define SHRT_HIGHBIT SHRT_MIN
94 #define MPN_ZERO(dst, n) memset((dst), 0, (n)*BYTES_PER_MP_LIMB)
95 #define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
96 #define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
97 #define MPN_COPY(dst,src,n) \
100 if ((dst) != (src)) \
102 MPFR_ASSERTD ((char *) (dst) >= (char *) (src) + \
103 (n) * BYTES_PER_MP_LIMB || \
104 (char *) (src) >= (char *) (dst) + \
105 (n) * BYTES_PER_MP_LIMB); \
106 memcpy ((dst), (src), (n) * BYTES_PER_MP_LIMB); \
112 #define MPN_NORMALIZE(DST, NLIMBS) \
116 if ((DST)[(NLIMBS) - 1] != 0) \
121 #define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
123 MPFR_ASSERTD ((NLIMBS) >= 1); \
126 if ((DST)[(NLIMBS) - 1] != 0) \
131 #define MPN_OVERLAP_P(xp, xsize, yp, ysize) \
132 ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
133 #define MPN_SAME_OR_INCR2_P(dst, dsize, src, ssize) \
134 ((dst) <= (src) || ! MPN_OVERLAP_P (dst, dsize, src, ssize))
135 #define MPN_SAME_OR_INCR_P(dst, src, size) \
136 MPN_SAME_OR_INCR2_P(dst, size, src, size)
137 #define MPN_SAME_OR_DECR2_P(dst, dsize, src, ssize) \
138 ((dst) >= (src) || ! MPN_OVERLAP_P (dst, dsize, src, ssize))
139 #define MPN_SAME_OR_DECR_P(dst, src, size) \
140 MPN_SAME_OR_DECR2_P(dst, size, src, size)
144 # define mpn_sqr_n(dst,src,n) mpn_mul((dst),(src),(n),(src),(n))
146 #ifndef mpn_mul_basecase
147 # define mpn_mul_basecase(dst,s1,n1,s2,n2) mpn_mul((dst),(s1),(n1),(s2),(n2))
149 #ifndef mpn_sqr_basecase
150 # define mpn_sqr_basecase(dst,src,n) mpn_mul((dst),(src),(n),(src),(n))
154 __MPFR_DECLSPEC
void mpfr_assert_fail _MPFR_PROTO( (
const char *,
int,
157 #define ASSERT_FAIL(expr) mpfr_assert_fail (__FILE__, __LINE__, #expr)
158 #define ASSERT(expr) MPFR_ASSERTD(expr)
161 #define SIZ(x) ((x)->_mp_size)
162 #define ABSIZ(x) ABS (SIZ (x))
163 #define PTR(x) ((x)->_mp_d)
164 #define LIMBS(x) ((x)->_mp_d)
165 #define EXP(x) ((x)->_mp_exp)
166 #define PREC(x) ((x)->_mp_prec)
168 #define MPZ_REALLOC(z,n) ((n) > ALLOC(z) ? _mpz_realloc(z,n) : PTR(z))
176 #define TMP_ALLOC(x) alloca(x)
181 #ifdef FEELPP_HAS_ATTRIBUTE_MODE
182 typedef unsigned int UQItype __attribute__ ( ( mode ( QI ) ) );
183 typedef int SItype __attribute__ ( ( mode ( SI ) ) );
184 typedef unsigned int USItype __attribute__ ( ( mode ( SI ) ) );
185 typedef int DItype __attribute__ ( ( mode ( DI ) ) );
186 typedef unsigned int UDItype __attribute__ ( ( mode ( DI ) ) );
188 typedef unsigned char UQItype;
190 typedef unsigned long USItype;
191 #ifdef FEELPP_HAS_LONG_LONG
192 typedef long long int DItype;
193 typedef unsigned long long int UDItype;
195 typedef long int DItype;
196 typedef unsigned long int UDItype;
199 typedef mp_limb_t UWtype;
200 typedef unsigned int UHWtype;
201 #define W_TYPE_SIZE BITS_PER_MP_LIMB
205 #define __clz_tab mpfr_clz_tab
209 #undef MP_BASE_AS_DOUBLE
210 #define MP_BASE_AS_DOUBLE (4.0 * ((mp_limb_t) 1 << (GMP_NUMB_BITS - 2)))
217 double chars_per_bit_exactly;
220 #define __mp_bases mpfr_bases
221 __MPFR_DECLSPEC
extern const struct bases mpfr_bases[257];
228 #define ABS(x) ((x) >= 0 ? (x) : -(x))
229 #define MIN(l,o) ((l) < (o) ? (l) : (o))
230 #define MAX(h,i) ((h) > (i) ? (h) : (i))
231 #define numberof(x) (sizeof (x) / sizeof ((x)[0]))
234 #undef __gmp_rands_initialized
236 #define __gmp_rands_initialized mpfr_rands_initialized
237 #define __gmp_rands mpfr_rands
239 __MPFR_DECLSPEC
extern char mpfr_rands_initialized;
240 __MPFR_DECLSPEC
extern gmp_randstate_t mpfr_rands;
244 ((__gmp_rands_initialized ? 0 \
245 : (__gmp_rands_initialized = 1, \
246 gmp_randinit_default (__gmp_rands), 0)), \
250 #define RANDS_CLEAR() \
252 if (__gmp_rands_initialized) \
254 __gmp_rands_initialized = 0; \
255 gmp_randclear (__gmp_rands); \
259 typedef __gmp_randstate_struct *gmp_randstate_ptr;
262 #define _gmp_rand mpfr_rand_raw
263 __MPFR_DECLSPEC
void mpfr_rand_raw _MPFR_PROTO( ( mp_ptr, gmp_randstate_t,
268 __MPFR_DECLSPEC
void mpfr_init_gmp_rand _MPFR_PROTO( (
void ) );
269 #define MPFR_TEST_USE_RANDS() mpfr_init_gmp_rand ();
277 #ifdef mp_get_memory_functions
279 #undef __gmp_allocate_func
280 #undef __gmp_reallocate_func
281 #undef __gmp_free_func
282 #define MPFR_GET_MEMFUNC mp_get_memory_functions(&mpfr_allocate_func, &mpfr_reallocate_func, &mpfr_free_func)
283 #define __gmp_allocate_func (MPFR_GET_MEMFUNC, mpfr_allocate_func)
284 #define __gmp_reallocate_func (MPFR_GET_MEMFUNC, mpfr_reallocate_func)
285 #define __gmp_free_func (MPFR_GET_MEMFUNC, mpfr_free_func)
286 __MPFR_DECLSPEC
extern void * ( *mpfr_allocate_func ) _MPFR_PROTO ( (
size_t ) );
287 __MPFR_DECLSPEC
extern void * ( *mpfr_reallocate_func ) _MPFR_PROTO ( (
void *,
289 __MPFR_DECLSPEC
extern void ( *mpfr_free_func ) _MPFR_PROTO ( (
void *,
294 #undef __gmp_default_allocate
295 #undef __gmp_default_reallocate
296 #undef __gmp_default_free
297 #define __gmp_default_allocate mpfr_default_allocate
298 #define __gmp_default_reallocate mpfr_default_reallocate
299 #define __gmp_default_free mpfr_default_free
300 __MPFR_DECLSPEC
void *__gmp_default_allocate _MPFR_PROTO ( (
size_t ) );
301 __MPFR_DECLSPEC
void *__gmp_default_reallocate _MPFR_PROTO ( (
void *,
size_t,
303 __MPFR_DECLSPEC
void __gmp_default_free _MPFR_PROTO ( (
void *,
size_t ) );
305 #if defined (__cplusplus)