1 /* Definitions for GNU multiple precision functions. -*- mode: c -*-
3 Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free
5 Software Foundation, Inc.
7 This file is part of the GNU MP Library.
9 The GNU MP 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 3 of the License, or (at your
12 option) any later version.
14 The GNU MP 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 GNU MP Library. If not, see http://www.gnu.org/licenses/. */
24 #if defined (__cplusplus)
25 #include <iosfwd> /* for std::istream, std::ostream, std::string */
30 /* Instantiated by configure. */
31 #if ! defined (__GMP_WITHIN_CONFIGURE)
32 #define __GMP_HAVE_HOST_CPU_FAMILY_power 0
33 #define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0
34 #define GMP_LIMB_BITS 32
35 #define GMP_NAIL_BITS 0
37 #define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS)
38 #define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS)
39 #define GMP_NUMB_MAX GMP_NUMB_MASK
40 #define GMP_NAIL_MASK (~ GMP_NUMB_MASK)
43 /* The following (everything under ifndef __GNU_MP__) must be identical in
44 gmp.h and mp.h to allow both to be included in an application or during
49 #define __need_size_t /* tell gcc stddef.h we only want size_t */
50 #if defined (__cplusplus)
51 #include <cstddef> /* for size_t */
53 #include <stddef.h> /* for size_t */
57 /* Instantiated by configure. */
58 #if ! defined (__GMP_WITHIN_CONFIGURE)
59 /* #undef _LONG_LONG_LIMB */
60 #define __GMP_LIBGMP_DLL 0
64 /* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in
65 all other circumstances.
67 When compiling objects for libgmp, __GMP_DECLSPEC is an export directive,
68 or when compiling for an application it's an import directive. The two
69 cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles
70 (and not defined from an application).
72 __GMP_DECLSPEC_XX is similarly used for libgmpxx. __GMP_WITHIN_GMPXX
73 indicates when building libgmpxx, and in that case libgmpxx functions are
74 exports, but libgmp functions which might get called are imports.
76 Libtool DLL_EXPORT define is not used.
78 There's no attempt to support GMP built both static and DLL. Doing so
79 would mean applications would have to tell us which of the two is going
80 to be used when linking, and that seems very tedious and error prone if
81 using GMP by hand, and equally tedious from a package since autoconf and
82 automake don't give much help.
84 __GMP_DECLSPEC is required on all documented global functions and
85 variables, the various internals in gmp-impl.h etc can be left unadorned.
86 But internals used by the test programs or speed measuring programs
87 should have __GMP_DECLSPEC, and certainly constants or variables must
88 have it or the wrong address will be resolved.
90 In gcc __declspec can go at either the start or end of a prototype.
92 In Microsoft C __declspec must go at the start, or after the type like
93 void __declspec(...) *foo()". There's no __dllexport or anything to
94 guard against someone foolish #defining dllexport. _export used to be
95 available, but no longer.
97 In Borland C _export still exists, but needs to go after the type, like
98 "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to
99 make use of that. Probably more trouble than it's worth. */
101 #if defined (__GNUC__)
102 #define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__)
103 #define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__)
105 #if defined (_MSC_VER) || defined (__BORLANDC__)
106 #define __GMP_DECLSPEC_EXPORT __declspec(dllexport)
107 #define __GMP_DECLSPEC_IMPORT __declspec(dllimport)
110 #define __GMP_DECLSPEC_EXPORT __export
111 #define __GMP_DECLSPEC_IMPORT __import
114 #define __GMP_DECLSPEC_EXPORT _Export
115 #define __GMP_DECLSPEC_IMPORT _Import
119 #ifdef __GMP_WITHIN_GMP
120 /* compiling to go into a DLL libgmp */
121 #define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT
123 /* compiling to go into an application which will link to a DLL libgmp */
124 #define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT
127 /* all other cases */
128 #define __GMP_DECLSPEC
132 #ifdef __GMP_SHORT_LIMB
133 typedef unsigned int mp_limb_t
;
134 typedef int mp_limb_signed_t
;
136 #ifdef _LONG_LONG_LIMB
137 typedef unsigned long long int mp_limb_t
;
138 typedef long long int mp_limb_signed_t
;
140 typedef unsigned long int mp_limb_t
;
141 typedef long int mp_limb_signed_t
;
144 typedef unsigned long int mp_bitcnt_t
;
146 /* For reference, note that the name __mpz_struct gets into C++ mangled
147 function names, which means although the "__" suggests an internal, we
148 must leave this name for binary compatibility. */
151 int _mp_alloc
; /* Number of *limbs* allocated and pointed
152 to by the _mp_d field. */
153 int _mp_size
; /* abs(_mp_size) is the number of limbs the
154 last field points to. If _mp_size is
155 negative this is a negative number. */
156 mp_limb_t
*_mp_d
; /* Pointer to the limbs. */
159 #endif /* __GNU_MP__ */
162 typedef __mpz_struct MP_INT
; /* gmp 1 source compatibility */
163 typedef __mpz_struct mpz_t
[1];
165 typedef mp_limb_t
* mp_ptr
;
166 typedef const mp_limb_t
* mp_srcptr
;
167 #if defined (_CRAY) && ! defined (_CRAYMPP)
168 /* plain `int' is much faster (48 bits) */
169 #define __GMP_MP_SIZE_T_INT 1
170 typedef int mp_size_t
;
171 typedef int mp_exp_t
;
173 #define __GMP_MP_SIZE_T_INT 0
174 typedef long int mp_size_t
;
175 typedef long int mp_exp_t
;
180 __mpz_struct _mp_num
;
181 __mpz_struct _mp_den
;
184 typedef __mpq_struct MP_RAT
; /* gmp 1 source compatibility */
185 typedef __mpq_struct mpq_t
[1];
189 int _mp_prec
; /* Max precision, in number of `mp_limb_t's.
190 Set by mpf_init and modified by
191 mpf_set_prec. The area pointed to by the
192 _mp_d field contains `prec' + 1 limbs. */
193 int _mp_size
; /* abs(_mp_size) is the number of limbs the
194 last field points to. If _mp_size is
195 negative this is a negative number. */
196 mp_exp_t _mp_exp
; /* Exponent, in the base of `mp_limb_t'. */
197 mp_limb_t
*_mp_d
; /* Pointer to the limbs. */
200 /* typedef __mpf_struct MP_FLOAT; */
201 typedef __mpf_struct mpf_t
[1];
203 /* Available random number generation algorithms. */
206 GMP_RAND_ALG_DEFAULT
= 0,
207 GMP_RAND_ALG_LC
= GMP_RAND_ALG_DEFAULT
/* Linear congruential. */
210 /* Random state struct. */
213 mpz_t _mp_seed
; /* _mp_d member points to state of the generator. */
214 gmp_randalg_t _mp_alg
; /* Currently unused. */
216 void *_mp_lc
; /* Pointer to function pointers structure. */
218 } __gmp_randstate_struct
;
219 typedef __gmp_randstate_struct gmp_randstate_t
[1];
221 /* Types for function declarations in gmp files. */
222 /* ??? Should not pollute user name space with these ??? */
223 typedef const __mpz_struct
*mpz_srcptr
;
224 typedef __mpz_struct
*mpz_ptr
;
225 typedef const __mpf_struct
*mpf_srcptr
;
226 typedef __mpf_struct
*mpf_ptr
;
227 typedef const __mpq_struct
*mpq_srcptr
;
228 typedef __mpq_struct
*mpq_ptr
;
231 /* This is not wanted in mp.h, so put it outside the __GNU_MP__ common
234 #ifdef __GMP_WITHIN_GMPXX
235 /* compiling to go into a DLL libgmpxx */
236 #define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT
238 /* compiling to go into a application which will link to a DLL libgmpxx */
239 #define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT
242 /* all other cases */
243 #define __GMP_DECLSPEC_XX
248 #define __MPN(x) __gmpn_##x
251 /* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
252 <iostream> defines EOF but not FILE. */
254 || defined (H_STDIO) \
255 || defined (_H_STDIO) /* AIX */ \
256 || defined (_STDIO_H) /* glibc, Sun, SCO */ \
257 || defined (_STDIO_H_) /* BSD, OSF */ \
258 || defined (__STDIO_H) /* Borland */ \
259 || defined (__STDIO_H__) /* IRIX */ \
260 || defined (_STDIO_INCLUDED) /* HPUX */ \
261 || defined (__dj_include_stdio_h_) /* DJGPP */ \
262 || defined (_FILE_DEFINED) /* Microsoft */ \
263 || defined (__STDIO__) /* Apple MPW MrC */ \
264 || defined (_MSL_STDIO_H) /* Metrowerks */ \
265 || defined (_STDIO_H_INCLUDED) /* QNX4 */ \
266 || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
267 || defined (__STDIO_LOADED) /* VMS */
268 #define _GMP_H_HAVE_FILE 1
271 /* In ISO C, if a prototype involving "struct obstack *" is given without
272 that structure defined, then the struct is scoped down to just the
273 prototype, causing a conflict if it's subsequently defined for real. So
274 only give prototypes if we've got obstack.h. */
275 #if defined (_OBSTACK_H) /* glibc <obstack.h> */
276 #define _GMP_H_HAVE_OBSTACK 1
279 /* The prototypes for gmp_vprintf etc are provided only if va_list is
280 available, via an application having included <stdarg.h> or <varargs.h>.
281 Usually va_list is a typedef so can't be tested directly, but C99
282 specifies that va_start is a macro (and it was normally a macro on past
283 systems too), so look for that.
285 <stdio.h> will define some sort of va_list for vprintf and vfprintf, but
286 let's not bother trying to use that since it's not standard and since
287 application uses for gmp_vprintf etc will almost certainly require the
288 whole <stdarg.h> or <varargs.h> anyway. */
291 #define _GMP_H_HAVE_VA_LIST 1
294 /* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */
295 #if defined (__GNUC__) && defined (__GNUC_MINOR__)
296 #define __GMP_GNUC_PREREQ(maj, min) \
297 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
299 #define __GMP_GNUC_PREREQ(maj, min) 0
302 /* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically
303 it means a function does nothing but examine its arguments and memory
304 (global or via arguments) to generate a return value, but changes nothing
305 and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets
306 tune/common.c etc turn this off when trying to write timing loops. */
307 #if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE)
308 #define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__))
310 #define __GMP_ATTRIBUTE_PURE
314 /* __GMP_CAST allows us to use static_cast in C++, so our macros are clean
315 to "g++ -Wold-style-cast".
317 Casts in "extern inline" code within an extern "C" block don't induce
318 these warnings, so __GMP_CAST only needs to be used on documented
322 #define __GMP_CAST(type, expr) (static_cast<type> (expr))
324 #define __GMP_CAST(type, expr) ((type) (expr))
328 /* An empty "throw ()" means the function doesn't throw any C++ exceptions,
329 this can save some stack frame info in applications.
331 Currently it's given only on functions which never divide-by-zero etc,
332 don't allocate memory, and are expected to never need to allocate memory.
333 This leaves open the possibility of a C++ throw from a future GMP
336 mpz_set_ui etc are omitted to leave open the lazy allocation scheme
337 described in doc/tasks.html. mpz_get_d etc are omitted to leave open
338 exceptions for float overflows.
340 Note that __GMP_NOTHROW must be given on any inlines the same as on their
341 prototypes (for g++ at least, where they're used together). Note also
342 that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like
343 __GMP_ATTRIBUTE_PURE. */
345 #if defined (__cplusplus)
346 #define __GMP_NOTHROW throw ()
348 #define __GMP_NOTHROW
352 /* PORTME: What other compilers have a useful "extern inline"? "static
353 inline" would be an acceptable substitute if the compiler (or linker)
354 discards unused statics. */
356 /* gcc has __inline__ in all modes, including strict ansi. Give a prototype
357 for an inline too, so as to correctly specify "dllimport" on windows, in
358 case the function is called rather than inlined.
359 GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
360 inline semantics, unless -fgnu89-inline is used. */
362 #if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2) \
363 || (defined __GNUC_GNU_INLINE__ && defined __cplusplus)
364 #define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__))
366 #define __GMP_EXTERN_INLINE extern __inline__
368 #define __GMP_INLINE_PROTOTYPES 1
371 /* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1
372 strict ANSI mode. Inlining is done even when not optimizing (ie. -O0
373 mode, which is the default), but an unnecessary local copy of foo is
374 emitted unless -O is used. "extern __inline" is accepted, but the
375 "extern" appears to be ignored, ie. it becomes a plain global function
376 but which is inlined within its file. Don't know if all old versions of
377 DEC C supported __inline, but as a start let's do the right thing for
380 #define __GMP_EXTERN_INLINE static __inline
383 /* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict
384 ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes
385 place under -O. Without -O "foo" seems to be emitted whether it's used
386 or not, which is wasteful. "extern inline foo()" isn't useful, the
387 "extern" is apparently ignored, so foo is inlined if possible but also
388 emitted as a global, which causes multiple definition errors when
389 building a shared libgmp. */
390 #ifdef __SCO_VERSION__
391 #if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \
392 && ! defined (__GMP_EXTERN_INLINE)
393 #define __GMP_EXTERN_INLINE static inline
397 /* Microsoft's C compiler accepts __inline */
399 #define __GMP_EXTERN_INLINE __inline
402 /* Recent enough Sun C compilers want "inline" */
403 #if defined (__SUNPRO_C) && __SUNPRO_C >= 0x560 \
404 && ! defined (__GMP_EXTERN_INLINE)
405 #define __GMP_EXTERN_INLINE inline
408 /* Somewhat older Sun C compilers want "static inline" */
409 #if defined (__SUNPRO_C) && __SUNPRO_C >= 0x540 \
410 && ! defined (__GMP_EXTERN_INLINE)
411 #define __GMP_EXTERN_INLINE static inline
415 /* C++ always has "inline" and since it's a normal feature the linker should
416 discard duplicate non-inlined copies, or if it doesn't then that's a
417 problem for everyone, not just GMP. */
418 #if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE)
419 #define __GMP_EXTERN_INLINE inline
422 /* Don't do any inlining within a configure run, since if the compiler ends
423 up emitting copies of the code into the object file it can end up
424 demanding the various support routines (like mpn_popcount) for linking,
425 making the "alloca" test and perhaps others fail. And on hppa ia64 a
426 pre-release gcc 3.2 was seen not respecting the "extern" in "extern
427 __inline__", triggering this problem too. */
428 #if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE
429 #undef __GMP_EXTERN_INLINE
432 /* By default, don't give a prototype when there's going to be an inline
433 version. Note in particular that Cray C++ objects to the combination of
434 prototype and inline. */
435 #ifdef __GMP_EXTERN_INLINE
436 #ifndef __GMP_INLINE_PROTOTYPES
437 #define __GMP_INLINE_PROTOTYPES 0
440 #define __GMP_INLINE_PROTOTYPES 1
444 #define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
445 #define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i))
447 /* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted
449 #define __GMP_UINT_MAX (~ (unsigned) 0)
450 #define __GMP_ULONG_MAX (~ (unsigned long) 0)
451 #define __GMP_USHRT_MAX ((unsigned short) ~0)
454 /* __builtin_expect is in gcc 3.0, and not in 2.95. */
455 #if __GMP_GNUC_PREREQ (3,0)
456 #define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1)
457 #define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0)
459 #define __GMP_LIKELY(cond) (cond)
460 #define __GMP_UNLIKELY(cond) (cond)
464 #define __GMP_CRAY_Pragma(str) _Pragma (str)
466 #define __GMP_CRAY_Pragma(str)
470 /* Allow direct user access to numerator and denominator of a mpq_t object. */
471 #define mpq_numref(Q) (&((Q)->_mp_num))
472 #define mpq_denref(Q) (&((Q)->_mp_den))
475 #if defined (__cplusplus)
480 #define mp_set_memory_functions __gmp_set_memory_functions
481 __GMP_DECLSPEC
void mp_set_memory_functions (void *(*) (size_t),
482 void *(*) (void *, size_t, size_t),
483 void (*) (void *, size_t)) __GMP_NOTHROW
;
485 #define mp_get_memory_functions __gmp_get_memory_functions
486 __GMP_DECLSPEC
void mp_get_memory_functions (void *(**) (size_t),
487 void *(**) (void *, size_t, size_t),
488 void (**) (void *, size_t)) __GMP_NOTHROW
;
490 #define mp_bits_per_limb __gmp_bits_per_limb
491 __GMP_DECLSPEC
extern const int mp_bits_per_limb
;
493 #define gmp_errno __gmp_errno
494 __GMP_DECLSPEC
extern int gmp_errno
;
496 #define gmp_version __gmp_version
497 __GMP_DECLSPEC
extern const char * const gmp_version
;
500 /**************** Random number routines. ****************/
503 #define gmp_randinit __gmp_randinit
504 __GMP_DECLSPEC
void gmp_randinit (gmp_randstate_t
, gmp_randalg_t
, ...);
506 #define gmp_randinit_default __gmp_randinit_default
507 __GMP_DECLSPEC
void gmp_randinit_default (gmp_randstate_t
);
509 #define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp
510 __GMP_DECLSPEC
void gmp_randinit_lc_2exp (gmp_randstate_t
, mpz_srcptr
, unsigned long int, mp_bitcnt_t
);
512 #define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size
513 __GMP_DECLSPEC
int gmp_randinit_lc_2exp_size (gmp_randstate_t
, mp_bitcnt_t
);
515 #define gmp_randinit_mt __gmp_randinit_mt
516 __GMP_DECLSPEC
void gmp_randinit_mt (gmp_randstate_t
);
518 #define gmp_randinit_set __gmp_randinit_set
519 __GMP_DECLSPEC
void gmp_randinit_set (gmp_randstate_t
, const __gmp_randstate_struct
*);
521 #define gmp_randseed __gmp_randseed
522 __GMP_DECLSPEC
void gmp_randseed (gmp_randstate_t
, mpz_srcptr
);
524 #define gmp_randseed_ui __gmp_randseed_ui
525 __GMP_DECLSPEC
void gmp_randseed_ui (gmp_randstate_t
, unsigned long int);
527 #define gmp_randclear __gmp_randclear
528 __GMP_DECLSPEC
void gmp_randclear (gmp_randstate_t
);
530 #define gmp_urandomb_ui __gmp_urandomb_ui
531 __GMP_DECLSPEC
unsigned long gmp_urandomb_ui (gmp_randstate_t
, unsigned long);
533 #define gmp_urandomm_ui __gmp_urandomm_ui
534 __GMP_DECLSPEC
unsigned long gmp_urandomm_ui (gmp_randstate_t
, unsigned long);
537 /**************** Formatted output routines. ****************/
539 #define gmp_asprintf __gmp_asprintf
540 __GMP_DECLSPEC
int gmp_asprintf (char **, const char *, ...);
542 #define gmp_fprintf __gmp_fprintf
543 #ifdef _GMP_H_HAVE_FILE
544 __GMP_DECLSPEC
int gmp_fprintf (FILE *, const char *, ...);
547 #define gmp_obstack_printf __gmp_obstack_printf
548 #if defined (_GMP_H_HAVE_OBSTACK)
549 __GMP_DECLSPEC
int gmp_obstack_printf (struct obstack
*, const char *, ...);
552 #define gmp_obstack_vprintf __gmp_obstack_vprintf
553 #if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST)
554 __GMP_DECLSPEC
int gmp_obstack_vprintf (struct obstack
*, const char *, va_list);
557 #define gmp_printf __gmp_printf
558 __GMP_DECLSPEC
int gmp_printf (const char *, ...);
560 #define gmp_snprintf __gmp_snprintf
561 __GMP_DECLSPEC
int gmp_snprintf (char *, size_t, const char *, ...);
563 #define gmp_sprintf __gmp_sprintf
564 __GMP_DECLSPEC
int gmp_sprintf (char *, const char *, ...);
566 #define gmp_vasprintf __gmp_vasprintf
567 #if defined (_GMP_H_HAVE_VA_LIST)
568 __GMP_DECLSPEC
int gmp_vasprintf (char **, const char *, va_list);
571 #define gmp_vfprintf __gmp_vfprintf
572 #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
573 __GMP_DECLSPEC
int gmp_vfprintf (FILE *, const char *, va_list);
576 #define gmp_vprintf __gmp_vprintf
577 #if defined (_GMP_H_HAVE_VA_LIST)
578 __GMP_DECLSPEC
int gmp_vprintf (const char *, va_list);
581 #define gmp_vsnprintf __gmp_vsnprintf
582 #if defined (_GMP_H_HAVE_VA_LIST)
583 __GMP_DECLSPEC
int gmp_vsnprintf (char *, size_t, const char *, va_list);
586 #define gmp_vsprintf __gmp_vsprintf
587 #if defined (_GMP_H_HAVE_VA_LIST)
588 __GMP_DECLSPEC
int gmp_vsprintf (char *, const char *, va_list);
592 /**************** Formatted input routines. ****************/
594 #define gmp_fscanf __gmp_fscanf
595 #ifdef _GMP_H_HAVE_FILE
596 __GMP_DECLSPEC
int gmp_fscanf (FILE *, const char *, ...);
599 #define gmp_scanf __gmp_scanf
600 __GMP_DECLSPEC
int gmp_scanf (const char *, ...);
602 #define gmp_sscanf __gmp_sscanf
603 __GMP_DECLSPEC
int gmp_sscanf (const char *, const char *, ...);
605 #define gmp_vfscanf __gmp_vfscanf
606 #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
607 __GMP_DECLSPEC
int gmp_vfscanf (FILE *, const char *, va_list);
610 #define gmp_vscanf __gmp_vscanf
611 #if defined (_GMP_H_HAVE_VA_LIST)
612 __GMP_DECLSPEC
int gmp_vscanf (const char *, va_list);
615 #define gmp_vsscanf __gmp_vsscanf
616 #if defined (_GMP_H_HAVE_VA_LIST)
617 __GMP_DECLSPEC
int gmp_vsscanf (const char *, const char *, va_list);
621 /**************** Integer (i.e. Z) routines. ****************/
623 #define _mpz_realloc __gmpz_realloc
624 #define mpz_realloc __gmpz_realloc
625 __GMP_DECLSPEC
void *_mpz_realloc (mpz_ptr
, mp_size_t
);
627 #define mpz_abs __gmpz_abs
628 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs)
629 __GMP_DECLSPEC
void mpz_abs (mpz_ptr
, mpz_srcptr
);
632 #define mpz_add __gmpz_add
633 __GMP_DECLSPEC
void mpz_add (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
635 #define mpz_add_ui __gmpz_add_ui
636 __GMP_DECLSPEC
void mpz_add_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
638 #define mpz_addmul __gmpz_addmul
639 __GMP_DECLSPEC
void mpz_addmul (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
641 #define mpz_addmul_ui __gmpz_addmul_ui
642 __GMP_DECLSPEC
void mpz_addmul_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
644 #define mpz_and __gmpz_and
645 __GMP_DECLSPEC
void mpz_and (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
647 #define mpz_array_init __gmpz_array_init
648 __GMP_DECLSPEC
void mpz_array_init (mpz_ptr
, mp_size_t
, mp_size_t
);
650 #define mpz_bin_ui __gmpz_bin_ui
651 __GMP_DECLSPEC
void mpz_bin_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
653 #define mpz_bin_uiui __gmpz_bin_uiui
654 __GMP_DECLSPEC
void mpz_bin_uiui (mpz_ptr
, unsigned long int, unsigned long int);
656 #define mpz_cdiv_q __gmpz_cdiv_q
657 __GMP_DECLSPEC
void mpz_cdiv_q (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
659 #define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp
660 __GMP_DECLSPEC
void mpz_cdiv_q_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
662 #define mpz_cdiv_q_ui __gmpz_cdiv_q_ui
663 __GMP_DECLSPEC
unsigned long int mpz_cdiv_q_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
665 #define mpz_cdiv_qr __gmpz_cdiv_qr
666 __GMP_DECLSPEC
void mpz_cdiv_qr (mpz_ptr
, mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
668 #define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui
669 __GMP_DECLSPEC
unsigned long int mpz_cdiv_qr_ui (mpz_ptr
, mpz_ptr
, mpz_srcptr
, unsigned long int);
671 #define mpz_cdiv_r __gmpz_cdiv_r
672 __GMP_DECLSPEC
void mpz_cdiv_r (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
674 #define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp
675 __GMP_DECLSPEC
void mpz_cdiv_r_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
677 #define mpz_cdiv_r_ui __gmpz_cdiv_r_ui
678 __GMP_DECLSPEC
unsigned long int mpz_cdiv_r_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
680 #define mpz_cdiv_ui __gmpz_cdiv_ui
681 __GMP_DECLSPEC
unsigned long int mpz_cdiv_ui (mpz_srcptr
, unsigned long int) __GMP_ATTRIBUTE_PURE
;
683 #define mpz_clear __gmpz_clear
684 __GMP_DECLSPEC
void mpz_clear (mpz_ptr
);
686 #define mpz_clears __gmpz_clears
687 __GMP_DECLSPEC
void mpz_clears (mpz_ptr
, ...);
689 #define mpz_clrbit __gmpz_clrbit
690 __GMP_DECLSPEC
void mpz_clrbit (mpz_ptr
, mp_bitcnt_t
);
692 #define mpz_cmp __gmpz_cmp
693 __GMP_DECLSPEC
int mpz_cmp (mpz_srcptr
, mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
695 #define mpz_cmp_d __gmpz_cmp_d
696 __GMP_DECLSPEC
int mpz_cmp_d (mpz_srcptr
, double) __GMP_ATTRIBUTE_PURE
;
698 #define _mpz_cmp_si __gmpz_cmp_si
699 __GMP_DECLSPEC
int _mpz_cmp_si (mpz_srcptr
, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
701 #define _mpz_cmp_ui __gmpz_cmp_ui
702 __GMP_DECLSPEC
int _mpz_cmp_ui (mpz_srcptr
, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
704 #define mpz_cmpabs __gmpz_cmpabs
705 __GMP_DECLSPEC
int mpz_cmpabs (mpz_srcptr
, mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
707 #define mpz_cmpabs_d __gmpz_cmpabs_d
708 __GMP_DECLSPEC
int mpz_cmpabs_d (mpz_srcptr
, double) __GMP_ATTRIBUTE_PURE
;
710 #define mpz_cmpabs_ui __gmpz_cmpabs_ui
711 __GMP_DECLSPEC
int mpz_cmpabs_ui (mpz_srcptr
, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
713 #define mpz_com __gmpz_com
714 __GMP_DECLSPEC
void mpz_com (mpz_ptr
, mpz_srcptr
);
716 #define mpz_combit __gmpz_combit
717 __GMP_DECLSPEC
void mpz_combit (mpz_ptr
, mp_bitcnt_t
);
719 #define mpz_congruent_p __gmpz_congruent_p
720 __GMP_DECLSPEC
int mpz_congruent_p (mpz_srcptr
, mpz_srcptr
, mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
722 #define mpz_congruent_2exp_p __gmpz_congruent_2exp_p
723 __GMP_DECLSPEC
int mpz_congruent_2exp_p (mpz_srcptr
, mpz_srcptr
, mp_bitcnt_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
725 #define mpz_congruent_ui_p __gmpz_congruent_ui_p
726 __GMP_DECLSPEC
int mpz_congruent_ui_p (mpz_srcptr
, unsigned long, unsigned long) __GMP_ATTRIBUTE_PURE
;
728 #define mpz_divexact __gmpz_divexact
729 __GMP_DECLSPEC
void mpz_divexact (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
731 #define mpz_divexact_ui __gmpz_divexact_ui
732 __GMP_DECLSPEC
void mpz_divexact_ui (mpz_ptr
, mpz_srcptr
, unsigned long);
734 #define mpz_divisible_p __gmpz_divisible_p
735 __GMP_DECLSPEC
int mpz_divisible_p (mpz_srcptr
, mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
737 #define mpz_divisible_ui_p __gmpz_divisible_ui_p
738 __GMP_DECLSPEC
int mpz_divisible_ui_p (mpz_srcptr
, unsigned long) __GMP_ATTRIBUTE_PURE
;
740 #define mpz_divisible_2exp_p __gmpz_divisible_2exp_p
741 __GMP_DECLSPEC
int mpz_divisible_2exp_p (mpz_srcptr
, mp_bitcnt_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
743 #define mpz_dump __gmpz_dump
744 __GMP_DECLSPEC
void mpz_dump (mpz_srcptr
);
746 #define mpz_export __gmpz_export
747 __GMP_DECLSPEC
void *mpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr
);
749 #define mpz_fac_ui __gmpz_fac_ui
750 __GMP_DECLSPEC
void mpz_fac_ui (mpz_ptr
, unsigned long int);
752 #define mpz_2fac_ui __gmpz_2fac_ui
753 __GMP_DECLSPEC
void mpz_2fac_ui (mpz_ptr
, unsigned long int);
755 #define mpz_mfac_uiui __gmpz_mfac_uiui
756 __GMP_DECLSPEC
void mpz_mfac_uiui (mpz_ptr
, unsigned long int, unsigned long int);
758 #define mpz_primorial_ui __gmpz_primorial_ui
759 __GMP_DECLSPEC
void mpz_primorial_ui (mpz_ptr
, unsigned long int);
761 #define mpz_fdiv_q __gmpz_fdiv_q
762 __GMP_DECLSPEC
void mpz_fdiv_q (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
764 #define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp
765 __GMP_DECLSPEC
void mpz_fdiv_q_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
767 #define mpz_fdiv_q_ui __gmpz_fdiv_q_ui
768 __GMP_DECLSPEC
unsigned long int mpz_fdiv_q_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
770 #define mpz_fdiv_qr __gmpz_fdiv_qr
771 __GMP_DECLSPEC
void mpz_fdiv_qr (mpz_ptr
, mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
773 #define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui
774 __GMP_DECLSPEC
unsigned long int mpz_fdiv_qr_ui (mpz_ptr
, mpz_ptr
, mpz_srcptr
, unsigned long int);
776 #define mpz_fdiv_r __gmpz_fdiv_r
777 __GMP_DECLSPEC
void mpz_fdiv_r (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
779 #define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp
780 __GMP_DECLSPEC
void mpz_fdiv_r_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
782 #define mpz_fdiv_r_ui __gmpz_fdiv_r_ui
783 __GMP_DECLSPEC
unsigned long int mpz_fdiv_r_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
785 #define mpz_fdiv_ui __gmpz_fdiv_ui
786 __GMP_DECLSPEC
unsigned long int mpz_fdiv_ui (mpz_srcptr
, unsigned long int) __GMP_ATTRIBUTE_PURE
;
788 #define mpz_fib_ui __gmpz_fib_ui
789 __GMP_DECLSPEC
void mpz_fib_ui (mpz_ptr
, unsigned long int);
791 #define mpz_fib2_ui __gmpz_fib2_ui
792 __GMP_DECLSPEC
void mpz_fib2_ui (mpz_ptr
, mpz_ptr
, unsigned long int);
794 #define mpz_fits_sint_p __gmpz_fits_sint_p
795 __GMP_DECLSPEC
int mpz_fits_sint_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
797 #define mpz_fits_slong_p __gmpz_fits_slong_p
798 __GMP_DECLSPEC
int mpz_fits_slong_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
800 #define mpz_fits_sshort_p __gmpz_fits_sshort_p
801 __GMP_DECLSPEC
int mpz_fits_sshort_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
803 #define mpz_fits_uint_p __gmpz_fits_uint_p
804 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p)
805 __GMP_DECLSPEC
int mpz_fits_uint_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
808 #define mpz_fits_ulong_p __gmpz_fits_ulong_p
809 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p)
810 __GMP_DECLSPEC
int mpz_fits_ulong_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
813 #define mpz_fits_ushort_p __gmpz_fits_ushort_p
814 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p)
815 __GMP_DECLSPEC
int mpz_fits_ushort_p (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
818 #define mpz_gcd __gmpz_gcd
819 __GMP_DECLSPEC
void mpz_gcd (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
821 #define mpz_gcd_ui __gmpz_gcd_ui
822 __GMP_DECLSPEC
unsigned long int mpz_gcd_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
824 #define mpz_gcdext __gmpz_gcdext
825 __GMP_DECLSPEC
void mpz_gcdext (mpz_ptr
, mpz_ptr
, mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
827 #define mpz_get_d __gmpz_get_d
828 __GMP_DECLSPEC
double mpz_get_d (mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
830 #define mpz_get_d_2exp __gmpz_get_d_2exp
831 __GMP_DECLSPEC
double mpz_get_d_2exp (signed long int *, mpz_srcptr
);
833 #define mpz_get_si __gmpz_get_si
834 __GMP_DECLSPEC
/* signed */ long int mpz_get_si (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
836 #define mpz_get_str __gmpz_get_str
837 __GMP_DECLSPEC
char *mpz_get_str (char *, int, mpz_srcptr
);
839 #define mpz_get_ui __gmpz_get_ui
840 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui)
841 __GMP_DECLSPEC
unsigned long int mpz_get_ui (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
844 #define mpz_getlimbn __gmpz_getlimbn
845 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn)
846 __GMP_DECLSPEC mp_limb_t
mpz_getlimbn (mpz_srcptr
, mp_size_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
849 #define mpz_hamdist __gmpz_hamdist
850 __GMP_DECLSPEC mp_bitcnt_t
mpz_hamdist (mpz_srcptr
, mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
852 #define mpz_import __gmpz_import
853 __GMP_DECLSPEC
void mpz_import (mpz_ptr
, size_t, int, size_t, int, size_t, const void *);
855 #define mpz_init __gmpz_init
856 __GMP_DECLSPEC
void mpz_init (mpz_ptr
);
858 #define mpz_init2 __gmpz_init2
859 __GMP_DECLSPEC
void mpz_init2 (mpz_ptr
, mp_bitcnt_t
);
861 #define mpz_inits __gmpz_inits
862 __GMP_DECLSPEC
void mpz_inits (mpz_ptr
, ...);
864 #define mpz_init_set __gmpz_init_set
865 __GMP_DECLSPEC
void mpz_init_set (mpz_ptr
, mpz_srcptr
);
867 #define mpz_init_set_d __gmpz_init_set_d
868 __GMP_DECLSPEC
void mpz_init_set_d (mpz_ptr
, double);
870 #define mpz_init_set_si __gmpz_init_set_si
871 __GMP_DECLSPEC
void mpz_init_set_si (mpz_ptr
, signed long int);
873 #define mpz_init_set_str __gmpz_init_set_str
874 __GMP_DECLSPEC
int mpz_init_set_str (mpz_ptr
, const char *, int);
876 #define mpz_init_set_ui __gmpz_init_set_ui
877 __GMP_DECLSPEC
void mpz_init_set_ui (mpz_ptr
, unsigned long int);
879 #define mpz_inp_raw __gmpz_inp_raw
880 #ifdef _GMP_H_HAVE_FILE
881 __GMP_DECLSPEC
size_t mpz_inp_raw (mpz_ptr
, FILE *);
884 #define mpz_inp_str __gmpz_inp_str
885 #ifdef _GMP_H_HAVE_FILE
886 __GMP_DECLSPEC
size_t mpz_inp_str (mpz_ptr
, FILE *, int);
889 #define mpz_invert __gmpz_invert
890 __GMP_DECLSPEC
int mpz_invert (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
892 #define mpz_ior __gmpz_ior
893 __GMP_DECLSPEC
void mpz_ior (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
895 #define mpz_jacobi __gmpz_jacobi
896 __GMP_DECLSPEC
int mpz_jacobi (mpz_srcptr
, mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
898 #define mpz_kronecker mpz_jacobi /* alias */
900 #define mpz_kronecker_si __gmpz_kronecker_si
901 __GMP_DECLSPEC
int mpz_kronecker_si (mpz_srcptr
, long) __GMP_ATTRIBUTE_PURE
;
903 #define mpz_kronecker_ui __gmpz_kronecker_ui
904 __GMP_DECLSPEC
int mpz_kronecker_ui (mpz_srcptr
, unsigned long) __GMP_ATTRIBUTE_PURE
;
906 #define mpz_si_kronecker __gmpz_si_kronecker
907 __GMP_DECLSPEC
int mpz_si_kronecker (long, mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
909 #define mpz_ui_kronecker __gmpz_ui_kronecker
910 __GMP_DECLSPEC
int mpz_ui_kronecker (unsigned long, mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
912 #define mpz_lcm __gmpz_lcm
913 __GMP_DECLSPEC
void mpz_lcm (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
915 #define mpz_lcm_ui __gmpz_lcm_ui
916 __GMP_DECLSPEC
void mpz_lcm_ui (mpz_ptr
, mpz_srcptr
, unsigned long);
918 #define mpz_legendre mpz_jacobi /* alias */
920 #define mpz_lucnum_ui __gmpz_lucnum_ui
921 __GMP_DECLSPEC
void mpz_lucnum_ui (mpz_ptr
, unsigned long int);
923 #define mpz_lucnum2_ui __gmpz_lucnum2_ui
924 __GMP_DECLSPEC
void mpz_lucnum2_ui (mpz_ptr
, mpz_ptr
, unsigned long int);
926 #define mpz_millerrabin __gmpz_millerrabin
927 __GMP_DECLSPEC
int mpz_millerrabin (mpz_srcptr
, int) __GMP_ATTRIBUTE_PURE
;
929 #define mpz_mod __gmpz_mod
930 __GMP_DECLSPEC
void mpz_mod (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
932 #define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */
934 #define mpz_mul __gmpz_mul
935 __GMP_DECLSPEC
void mpz_mul (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
937 #define mpz_mul_2exp __gmpz_mul_2exp
938 __GMP_DECLSPEC
void mpz_mul_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
940 #define mpz_mul_si __gmpz_mul_si
941 __GMP_DECLSPEC
void mpz_mul_si (mpz_ptr
, mpz_srcptr
, long int);
943 #define mpz_mul_ui __gmpz_mul_ui
944 __GMP_DECLSPEC
void mpz_mul_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
946 #define mpz_neg __gmpz_neg
947 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg)
948 __GMP_DECLSPEC
void mpz_neg (mpz_ptr
, mpz_srcptr
);
951 #define mpz_nextprime __gmpz_nextprime
952 __GMP_DECLSPEC
void mpz_nextprime (mpz_ptr
, mpz_srcptr
);
954 #define mpz_out_raw __gmpz_out_raw
955 #ifdef _GMP_H_HAVE_FILE
956 __GMP_DECLSPEC
size_t mpz_out_raw (FILE *, mpz_srcptr
);
959 #define mpz_out_str __gmpz_out_str
960 #ifdef _GMP_H_HAVE_FILE
961 __GMP_DECLSPEC
size_t mpz_out_str (FILE *, int, mpz_srcptr
);
964 #define mpz_perfect_power_p __gmpz_perfect_power_p
965 __GMP_DECLSPEC
int mpz_perfect_power_p (mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
967 #define mpz_perfect_square_p __gmpz_perfect_square_p
968 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p)
969 __GMP_DECLSPEC
int mpz_perfect_square_p (mpz_srcptr
) __GMP_ATTRIBUTE_PURE
;
972 #define mpz_popcount __gmpz_popcount
973 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount)
974 __GMP_DECLSPEC mp_bitcnt_t
mpz_popcount (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
977 #define mpz_pow_ui __gmpz_pow_ui
978 __GMP_DECLSPEC
void mpz_pow_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
980 #define mpz_powm __gmpz_powm
981 __GMP_DECLSPEC
void mpz_powm (mpz_ptr
, mpz_srcptr
, mpz_srcptr
, mpz_srcptr
);
983 #define mpz_powm_sec __gmpz_powm_sec
984 __GMP_DECLSPEC
void mpz_powm_sec (mpz_ptr
, mpz_srcptr
, mpz_srcptr
, mpz_srcptr
);
986 #define mpz_powm_ui __gmpz_powm_ui
987 __GMP_DECLSPEC
void mpz_powm_ui (mpz_ptr
, mpz_srcptr
, unsigned long int, mpz_srcptr
);
989 #define mpz_probab_prime_p __gmpz_probab_prime_p
990 __GMP_DECLSPEC
int mpz_probab_prime_p (mpz_srcptr
, int) __GMP_ATTRIBUTE_PURE
;
992 #define mpz_random __gmpz_random
993 __GMP_DECLSPEC
void mpz_random (mpz_ptr
, mp_size_t
);
995 #define mpz_random2 __gmpz_random2
996 __GMP_DECLSPEC
void mpz_random2 (mpz_ptr
, mp_size_t
);
998 #define mpz_realloc2 __gmpz_realloc2
999 __GMP_DECLSPEC
void mpz_realloc2 (mpz_ptr
, mp_bitcnt_t
);
1001 #define mpz_remove __gmpz_remove
1002 __GMP_DECLSPEC mp_bitcnt_t
mpz_remove (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1004 #define mpz_root __gmpz_root
1005 __GMP_DECLSPEC
int mpz_root (mpz_ptr
, mpz_srcptr
, unsigned long int);
1007 #define mpz_rootrem __gmpz_rootrem
1008 __GMP_DECLSPEC
void mpz_rootrem (mpz_ptr
, mpz_ptr
, mpz_srcptr
, unsigned long int);
1010 #define mpz_rrandomb __gmpz_rrandomb
1011 __GMP_DECLSPEC
void mpz_rrandomb (mpz_ptr
, gmp_randstate_t
, mp_bitcnt_t
);
1013 #define mpz_scan0 __gmpz_scan0
1014 __GMP_DECLSPEC mp_bitcnt_t
mpz_scan0 (mpz_srcptr
, mp_bitcnt_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1016 #define mpz_scan1 __gmpz_scan1
1017 __GMP_DECLSPEC mp_bitcnt_t
mpz_scan1 (mpz_srcptr
, mp_bitcnt_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1019 #define mpz_set __gmpz_set
1020 __GMP_DECLSPEC
void mpz_set (mpz_ptr
, mpz_srcptr
);
1022 #define mpz_set_d __gmpz_set_d
1023 __GMP_DECLSPEC
void mpz_set_d (mpz_ptr
, double);
1025 #define mpz_set_f __gmpz_set_f
1026 __GMP_DECLSPEC
void mpz_set_f (mpz_ptr
, mpf_srcptr
);
1028 #define mpz_set_q __gmpz_set_q
1029 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q)
1030 __GMP_DECLSPEC
void mpz_set_q (mpz_ptr
, mpq_srcptr
);
1033 #define mpz_set_si __gmpz_set_si
1034 __GMP_DECLSPEC
void mpz_set_si (mpz_ptr
, signed long int);
1036 #define mpz_set_str __gmpz_set_str
1037 __GMP_DECLSPEC
int mpz_set_str (mpz_ptr
, const char *, int);
1039 #define mpz_set_ui __gmpz_set_ui
1040 __GMP_DECLSPEC
void mpz_set_ui (mpz_ptr
, unsigned long int);
1042 #define mpz_setbit __gmpz_setbit
1043 __GMP_DECLSPEC
void mpz_setbit (mpz_ptr
, mp_bitcnt_t
);
1045 #define mpz_size __gmpz_size
1046 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size)
1047 __GMP_DECLSPEC
size_t mpz_size (mpz_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1050 #define mpz_sizeinbase __gmpz_sizeinbase
1051 __GMP_DECLSPEC
size_t mpz_sizeinbase (mpz_srcptr
, int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1053 #define mpz_sqrt __gmpz_sqrt
1054 __GMP_DECLSPEC
void mpz_sqrt (mpz_ptr
, mpz_srcptr
);
1056 #define mpz_sqrtrem __gmpz_sqrtrem
1057 __GMP_DECLSPEC
void mpz_sqrtrem (mpz_ptr
, mpz_ptr
, mpz_srcptr
);
1059 #define mpz_sub __gmpz_sub
1060 __GMP_DECLSPEC
void mpz_sub (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1062 #define mpz_sub_ui __gmpz_sub_ui
1063 __GMP_DECLSPEC
void mpz_sub_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
1065 #define mpz_ui_sub __gmpz_ui_sub
1066 __GMP_DECLSPEC
void mpz_ui_sub (mpz_ptr
, unsigned long int, mpz_srcptr
);
1068 #define mpz_submul __gmpz_submul
1069 __GMP_DECLSPEC
void mpz_submul (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1071 #define mpz_submul_ui __gmpz_submul_ui
1072 __GMP_DECLSPEC
void mpz_submul_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
1074 #define mpz_swap __gmpz_swap
1075 __GMP_DECLSPEC
void mpz_swap (mpz_ptr
, mpz_ptr
) __GMP_NOTHROW
;
1077 #define mpz_tdiv_ui __gmpz_tdiv_ui
1078 __GMP_DECLSPEC
unsigned long int mpz_tdiv_ui (mpz_srcptr
, unsigned long int) __GMP_ATTRIBUTE_PURE
;
1080 #define mpz_tdiv_q __gmpz_tdiv_q
1081 __GMP_DECLSPEC
void mpz_tdiv_q (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1083 #define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp
1084 __GMP_DECLSPEC
void mpz_tdiv_q_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
1086 #define mpz_tdiv_q_ui __gmpz_tdiv_q_ui
1087 __GMP_DECLSPEC
unsigned long int mpz_tdiv_q_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
1089 #define mpz_tdiv_qr __gmpz_tdiv_qr
1090 __GMP_DECLSPEC
void mpz_tdiv_qr (mpz_ptr
, mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1092 #define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui
1093 __GMP_DECLSPEC
unsigned long int mpz_tdiv_qr_ui (mpz_ptr
, mpz_ptr
, mpz_srcptr
, unsigned long int);
1095 #define mpz_tdiv_r __gmpz_tdiv_r
1096 __GMP_DECLSPEC
void mpz_tdiv_r (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1098 #define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp
1099 __GMP_DECLSPEC
void mpz_tdiv_r_2exp (mpz_ptr
, mpz_srcptr
, mp_bitcnt_t
);
1101 #define mpz_tdiv_r_ui __gmpz_tdiv_r_ui
1102 __GMP_DECLSPEC
unsigned long int mpz_tdiv_r_ui (mpz_ptr
, mpz_srcptr
, unsigned long int);
1104 #define mpz_tstbit __gmpz_tstbit
1105 __GMP_DECLSPEC
int mpz_tstbit (mpz_srcptr
, mp_bitcnt_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1107 #define mpz_ui_pow_ui __gmpz_ui_pow_ui
1108 __GMP_DECLSPEC
void mpz_ui_pow_ui (mpz_ptr
, unsigned long int, unsigned long int);
1110 #define mpz_urandomb __gmpz_urandomb
1111 __GMP_DECLSPEC
void mpz_urandomb (mpz_ptr
, gmp_randstate_t
, mp_bitcnt_t
);
1113 #define mpz_urandomm __gmpz_urandomm
1114 __GMP_DECLSPEC
void mpz_urandomm (mpz_ptr
, gmp_randstate_t
, mpz_srcptr
);
1116 #define mpz_xor __gmpz_xor
1117 #define mpz_eor __gmpz_xor
1118 __GMP_DECLSPEC
void mpz_xor (mpz_ptr
, mpz_srcptr
, mpz_srcptr
);
1121 /**************** Rational (i.e. Q) routines. ****************/
1123 #define mpq_abs __gmpq_abs
1124 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs)
1125 __GMP_DECLSPEC
void mpq_abs (mpq_ptr
, mpq_srcptr
);
1128 #define mpq_add __gmpq_add
1129 __GMP_DECLSPEC
void mpq_add (mpq_ptr
, mpq_srcptr
, mpq_srcptr
);
1131 #define mpq_canonicalize __gmpq_canonicalize
1132 __GMP_DECLSPEC
void mpq_canonicalize (mpq_ptr
);
1134 #define mpq_clear __gmpq_clear
1135 __GMP_DECLSPEC
void mpq_clear (mpq_ptr
);
1137 #define mpq_clears __gmpq_clears
1138 __GMP_DECLSPEC
void mpq_clears (mpq_ptr
, ...);
1140 #define mpq_cmp __gmpq_cmp
1141 __GMP_DECLSPEC
int mpq_cmp (mpq_srcptr
, mpq_srcptr
) __GMP_ATTRIBUTE_PURE
;
1143 #define _mpq_cmp_si __gmpq_cmp_si
1144 __GMP_DECLSPEC
int _mpq_cmp_si (mpq_srcptr
, long, unsigned long) __GMP_ATTRIBUTE_PURE
;
1146 #define _mpq_cmp_ui __gmpq_cmp_ui
1147 __GMP_DECLSPEC
int _mpq_cmp_ui (mpq_srcptr
, unsigned long int, unsigned long int) __GMP_ATTRIBUTE_PURE
;
1149 #define mpq_div __gmpq_div
1150 __GMP_DECLSPEC
void mpq_div (mpq_ptr
, mpq_srcptr
, mpq_srcptr
);
1152 #define mpq_div_2exp __gmpq_div_2exp
1153 __GMP_DECLSPEC
void mpq_div_2exp (mpq_ptr
, mpq_srcptr
, mp_bitcnt_t
);
1155 #define mpq_equal __gmpq_equal
1156 __GMP_DECLSPEC
int mpq_equal (mpq_srcptr
, mpq_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1158 #define mpq_get_num __gmpq_get_num
1159 __GMP_DECLSPEC
void mpq_get_num (mpz_ptr
, mpq_srcptr
);
1161 #define mpq_get_den __gmpq_get_den
1162 __GMP_DECLSPEC
void mpq_get_den (mpz_ptr
, mpq_srcptr
);
1164 #define mpq_get_d __gmpq_get_d
1165 __GMP_DECLSPEC
double mpq_get_d (mpq_srcptr
) __GMP_ATTRIBUTE_PURE
;
1167 #define mpq_get_str __gmpq_get_str
1168 __GMP_DECLSPEC
char *mpq_get_str (char *, int, mpq_srcptr
);
1170 #define mpq_init __gmpq_init
1171 __GMP_DECLSPEC
void mpq_init (mpq_ptr
);
1173 #define mpq_inits __gmpq_inits
1174 __GMP_DECLSPEC
void mpq_inits (mpq_ptr
, ...);
1176 #define mpq_inp_str __gmpq_inp_str
1177 #ifdef _GMP_H_HAVE_FILE
1178 __GMP_DECLSPEC
size_t mpq_inp_str (mpq_ptr
, FILE *, int);
1181 #define mpq_inv __gmpq_inv
1182 __GMP_DECLSPEC
void mpq_inv (mpq_ptr
, mpq_srcptr
);
1184 #define mpq_mul __gmpq_mul
1185 __GMP_DECLSPEC
void mpq_mul (mpq_ptr
, mpq_srcptr
, mpq_srcptr
);
1187 #define mpq_mul_2exp __gmpq_mul_2exp
1188 __GMP_DECLSPEC
void mpq_mul_2exp (mpq_ptr
, mpq_srcptr
, mp_bitcnt_t
);
1190 #define mpq_neg __gmpq_neg
1191 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg)
1192 __GMP_DECLSPEC
void mpq_neg (mpq_ptr
, mpq_srcptr
);
1195 #define mpq_out_str __gmpq_out_str
1196 #ifdef _GMP_H_HAVE_FILE
1197 __GMP_DECLSPEC
size_t mpq_out_str (FILE *, int, mpq_srcptr
);
1200 #define mpq_set __gmpq_set
1201 __GMP_DECLSPEC
void mpq_set (mpq_ptr
, mpq_srcptr
);
1203 #define mpq_set_d __gmpq_set_d
1204 __GMP_DECLSPEC
void mpq_set_d (mpq_ptr
, double);
1206 #define mpq_set_den __gmpq_set_den
1207 __GMP_DECLSPEC
void mpq_set_den (mpq_ptr
, mpz_srcptr
);
1209 #define mpq_set_f __gmpq_set_f
1210 __GMP_DECLSPEC
void mpq_set_f (mpq_ptr
, mpf_srcptr
);
1212 #define mpq_set_num __gmpq_set_num
1213 __GMP_DECLSPEC
void mpq_set_num (mpq_ptr
, mpz_srcptr
);
1215 #define mpq_set_si __gmpq_set_si
1216 __GMP_DECLSPEC
void mpq_set_si (mpq_ptr
, signed long int, unsigned long int);
1218 #define mpq_set_str __gmpq_set_str
1219 __GMP_DECLSPEC
int mpq_set_str (mpq_ptr
, const char *, int);
1221 #define mpq_set_ui __gmpq_set_ui
1222 __GMP_DECLSPEC
void mpq_set_ui (mpq_ptr
, unsigned long int, unsigned long int);
1224 #define mpq_set_z __gmpq_set_z
1225 __GMP_DECLSPEC
void mpq_set_z (mpq_ptr
, mpz_srcptr
);
1227 #define mpq_sub __gmpq_sub
1228 __GMP_DECLSPEC
void mpq_sub (mpq_ptr
, mpq_srcptr
, mpq_srcptr
);
1230 #define mpq_swap __gmpq_swap
1231 __GMP_DECLSPEC
void mpq_swap (mpq_ptr
, mpq_ptr
) __GMP_NOTHROW
;
1234 /**************** Float (i.e. F) routines. ****************/
1236 #define mpf_abs __gmpf_abs
1237 __GMP_DECLSPEC
void mpf_abs (mpf_ptr
, mpf_srcptr
);
1239 #define mpf_add __gmpf_add
1240 __GMP_DECLSPEC
void mpf_add (mpf_ptr
, mpf_srcptr
, mpf_srcptr
);
1242 #define mpf_add_ui __gmpf_add_ui
1243 __GMP_DECLSPEC
void mpf_add_ui (mpf_ptr
, mpf_srcptr
, unsigned long int);
1244 #define mpf_ceil __gmpf_ceil
1245 __GMP_DECLSPEC
void mpf_ceil (mpf_ptr
, mpf_srcptr
);
1247 #define mpf_clear __gmpf_clear
1248 __GMP_DECLSPEC
void mpf_clear (mpf_ptr
);
1250 #define mpf_clears __gmpf_clears
1251 __GMP_DECLSPEC
void mpf_clears (mpf_ptr
, ...);
1253 #define mpf_cmp __gmpf_cmp
1254 __GMP_DECLSPEC
int mpf_cmp (mpf_srcptr
, mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1256 #define mpf_cmp_d __gmpf_cmp_d
1257 __GMP_DECLSPEC
int mpf_cmp_d (mpf_srcptr
, double) __GMP_ATTRIBUTE_PURE
;
1259 #define mpf_cmp_si __gmpf_cmp_si
1260 __GMP_DECLSPEC
int mpf_cmp_si (mpf_srcptr
, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1262 #define mpf_cmp_ui __gmpf_cmp_ui
1263 __GMP_DECLSPEC
int mpf_cmp_ui (mpf_srcptr
, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1265 #define mpf_div __gmpf_div
1266 __GMP_DECLSPEC
void mpf_div (mpf_ptr
, mpf_srcptr
, mpf_srcptr
);
1268 #define mpf_div_2exp __gmpf_div_2exp
1269 __GMP_DECLSPEC
void mpf_div_2exp (mpf_ptr
, mpf_srcptr
, mp_bitcnt_t
);
1271 #define mpf_div_ui __gmpf_div_ui
1272 __GMP_DECLSPEC
void mpf_div_ui (mpf_ptr
, mpf_srcptr
, unsigned long int);
1274 #define mpf_dump __gmpf_dump
1275 __GMP_DECLSPEC
void mpf_dump (mpf_srcptr
);
1277 #define mpf_eq __gmpf_eq
1278 __GMP_DECLSPEC
int mpf_eq (mpf_srcptr
, mpf_srcptr
, mp_bitcnt_t
) __GMP_ATTRIBUTE_PURE
;
1280 #define mpf_fits_sint_p __gmpf_fits_sint_p
1281 __GMP_DECLSPEC
int mpf_fits_sint_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1283 #define mpf_fits_slong_p __gmpf_fits_slong_p
1284 __GMP_DECLSPEC
int mpf_fits_slong_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1286 #define mpf_fits_sshort_p __gmpf_fits_sshort_p
1287 __GMP_DECLSPEC
int mpf_fits_sshort_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1289 #define mpf_fits_uint_p __gmpf_fits_uint_p
1290 __GMP_DECLSPEC
int mpf_fits_uint_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1292 #define mpf_fits_ulong_p __gmpf_fits_ulong_p
1293 __GMP_DECLSPEC
int mpf_fits_ulong_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1295 #define mpf_fits_ushort_p __gmpf_fits_ushort_p
1296 __GMP_DECLSPEC
int mpf_fits_ushort_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1298 #define mpf_floor __gmpf_floor
1299 __GMP_DECLSPEC
void mpf_floor (mpf_ptr
, mpf_srcptr
);
1301 #define mpf_get_d __gmpf_get_d
1302 __GMP_DECLSPEC
double mpf_get_d (mpf_srcptr
) __GMP_ATTRIBUTE_PURE
;
1304 #define mpf_get_d_2exp __gmpf_get_d_2exp
1305 __GMP_DECLSPEC
double mpf_get_d_2exp (signed long int *, mpf_srcptr
);
1307 #define mpf_get_default_prec __gmpf_get_default_prec
1308 __GMP_DECLSPEC mp_bitcnt_t
mpf_get_default_prec (void) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1310 #define mpf_get_prec __gmpf_get_prec
1311 __GMP_DECLSPEC mp_bitcnt_t
mpf_get_prec (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1313 #define mpf_get_si __gmpf_get_si
1314 __GMP_DECLSPEC
long mpf_get_si (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1316 #define mpf_get_str __gmpf_get_str
1317 __GMP_DECLSPEC
char *mpf_get_str (char *, mp_exp_t
*, int, size_t, mpf_srcptr
);
1319 #define mpf_get_ui __gmpf_get_ui
1320 __GMP_DECLSPEC
unsigned long mpf_get_ui (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1322 #define mpf_init __gmpf_init
1323 __GMP_DECLSPEC
void mpf_init (mpf_ptr
);
1325 #define mpf_init2 __gmpf_init2
1326 __GMP_DECLSPEC
void mpf_init2 (mpf_ptr
, mp_bitcnt_t
);
1328 #define mpf_inits __gmpf_inits
1329 __GMP_DECLSPEC
void mpf_inits (mpf_ptr
, ...);
1331 #define mpf_init_set __gmpf_init_set
1332 __GMP_DECLSPEC
void mpf_init_set (mpf_ptr
, mpf_srcptr
);
1334 #define mpf_init_set_d __gmpf_init_set_d
1335 __GMP_DECLSPEC
void mpf_init_set_d (mpf_ptr
, double);
1337 #define mpf_init_set_si __gmpf_init_set_si
1338 __GMP_DECLSPEC
void mpf_init_set_si (mpf_ptr
, signed long int);
1340 #define mpf_init_set_str __gmpf_init_set_str
1341 __GMP_DECLSPEC
int mpf_init_set_str (mpf_ptr
, const char *, int);
1343 #define mpf_init_set_ui __gmpf_init_set_ui
1344 __GMP_DECLSPEC
void mpf_init_set_ui (mpf_ptr
, unsigned long int);
1346 #define mpf_inp_str __gmpf_inp_str
1347 #ifdef _GMP_H_HAVE_FILE
1348 __GMP_DECLSPEC
size_t mpf_inp_str (mpf_ptr
, FILE *, int);
1351 #define mpf_integer_p __gmpf_integer_p
1352 __GMP_DECLSPEC
int mpf_integer_p (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1354 #define mpf_mul __gmpf_mul
1355 __GMP_DECLSPEC
void mpf_mul (mpf_ptr
, mpf_srcptr
, mpf_srcptr
);
1357 #define mpf_mul_2exp __gmpf_mul_2exp
1358 __GMP_DECLSPEC
void mpf_mul_2exp (mpf_ptr
, mpf_srcptr
, mp_bitcnt_t
);
1360 #define mpf_mul_ui __gmpf_mul_ui
1361 __GMP_DECLSPEC
void mpf_mul_ui (mpf_ptr
, mpf_srcptr
, unsigned long int);
1363 #define mpf_neg __gmpf_neg
1364 __GMP_DECLSPEC
void mpf_neg (mpf_ptr
, mpf_srcptr
);
1366 #define mpf_out_str __gmpf_out_str
1367 #ifdef _GMP_H_HAVE_FILE
1368 __GMP_DECLSPEC
size_t mpf_out_str (FILE *, int, size_t, mpf_srcptr
);
1371 #define mpf_pow_ui __gmpf_pow_ui
1372 __GMP_DECLSPEC
void mpf_pow_ui (mpf_ptr
, mpf_srcptr
, unsigned long int);
1374 #define mpf_random2 __gmpf_random2
1375 __GMP_DECLSPEC
void mpf_random2 (mpf_ptr
, mp_size_t
, mp_exp_t
);
1377 #define mpf_reldiff __gmpf_reldiff
1378 __GMP_DECLSPEC
void mpf_reldiff (mpf_ptr
, mpf_srcptr
, mpf_srcptr
);
1380 #define mpf_set __gmpf_set
1381 __GMP_DECLSPEC
void mpf_set (mpf_ptr
, mpf_srcptr
);
1383 #define mpf_set_d __gmpf_set_d
1384 __GMP_DECLSPEC
void mpf_set_d (mpf_ptr
, double);
1386 #define mpf_set_default_prec __gmpf_set_default_prec
1387 __GMP_DECLSPEC
void mpf_set_default_prec (mp_bitcnt_t
) __GMP_NOTHROW
;
1389 #define mpf_set_prec __gmpf_set_prec
1390 __GMP_DECLSPEC
void mpf_set_prec (mpf_ptr
, mp_bitcnt_t
);
1392 #define mpf_set_prec_raw __gmpf_set_prec_raw
1393 __GMP_DECLSPEC
void mpf_set_prec_raw (mpf_ptr
, mp_bitcnt_t
) __GMP_NOTHROW
;
1395 #define mpf_set_q __gmpf_set_q
1396 __GMP_DECLSPEC
void mpf_set_q (mpf_ptr
, mpq_srcptr
);
1398 #define mpf_set_si __gmpf_set_si
1399 __GMP_DECLSPEC
void mpf_set_si (mpf_ptr
, signed long int);
1401 #define mpf_set_str __gmpf_set_str
1402 __GMP_DECLSPEC
int mpf_set_str (mpf_ptr
, const char *, int);
1404 #define mpf_set_ui __gmpf_set_ui
1405 __GMP_DECLSPEC
void mpf_set_ui (mpf_ptr
, unsigned long int);
1407 #define mpf_set_z __gmpf_set_z
1408 __GMP_DECLSPEC
void mpf_set_z (mpf_ptr
, mpz_srcptr
);
1410 #define mpf_size __gmpf_size
1411 __GMP_DECLSPEC
size_t mpf_size (mpf_srcptr
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1413 #define mpf_sqrt __gmpf_sqrt
1414 __GMP_DECLSPEC
void mpf_sqrt (mpf_ptr
, mpf_srcptr
);
1416 #define mpf_sqrt_ui __gmpf_sqrt_ui
1417 __GMP_DECLSPEC
void mpf_sqrt_ui (mpf_ptr
, unsigned long int);
1419 #define mpf_sub __gmpf_sub
1420 __GMP_DECLSPEC
void mpf_sub (mpf_ptr
, mpf_srcptr
, mpf_srcptr
);
1422 #define mpf_sub_ui __gmpf_sub_ui
1423 __GMP_DECLSPEC
void mpf_sub_ui (mpf_ptr
, mpf_srcptr
, unsigned long int);
1425 #define mpf_swap __gmpf_swap
1426 __GMP_DECLSPEC
void mpf_swap (mpf_ptr
, mpf_ptr
) __GMP_NOTHROW
;
1428 #define mpf_trunc __gmpf_trunc
1429 __GMP_DECLSPEC
void mpf_trunc (mpf_ptr
, mpf_srcptr
);
1431 #define mpf_ui_div __gmpf_ui_div
1432 __GMP_DECLSPEC
void mpf_ui_div (mpf_ptr
, unsigned long int, mpf_srcptr
);
1434 #define mpf_ui_sub __gmpf_ui_sub
1435 __GMP_DECLSPEC
void mpf_ui_sub (mpf_ptr
, unsigned long int, mpf_srcptr
);
1437 #define mpf_urandomb __gmpf_urandomb
1438 __GMP_DECLSPEC
void mpf_urandomb (mpf_t
, gmp_randstate_t
, mp_bitcnt_t
);
1441 /************ Low level positive-integer (i.e. N) routines. ************/
1443 /* This is ugly, but we need to make user calls reach the prefixed function. */
1445 #define mpn_add __MPN(add)
1446 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add)
1447 __GMP_DECLSPEC mp_limb_t
mpn_add (mp_ptr
, mp_srcptr
, mp_size_t
, mp_srcptr
, mp_size_t
);
1450 #define mpn_add_1 __MPN(add_1)
1451 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1)
1452 __GMP_DECLSPEC mp_limb_t
mpn_add_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
) __GMP_NOTHROW
;
1455 #define mpn_add_n __MPN(add_n)
1456 __GMP_DECLSPEC mp_limb_t
mpn_add_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1458 #define mpn_addmul_1 __MPN(addmul_1)
1459 __GMP_DECLSPEC mp_limb_t
mpn_addmul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
);
1461 #define mpn_cmp __MPN(cmp)
1462 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp)
1463 __GMP_DECLSPEC
int mpn_cmp (mp_srcptr
, mp_srcptr
, mp_size_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1466 #define mpn_divexact_by3(dst,src,size) \
1467 mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0))
1469 #define mpn_divexact_by3c __MPN(divexact_by3c)
1470 __GMP_DECLSPEC mp_limb_t
mpn_divexact_by3c (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
);
1472 #define mpn_divmod_1(qp,np,nsize,dlimb) \
1473 mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb)
1475 #define mpn_divrem __MPN(divrem)
1476 __GMP_DECLSPEC mp_limb_t
mpn_divrem (mp_ptr
, mp_size_t
, mp_ptr
, mp_size_t
, mp_srcptr
, mp_size_t
);
1478 #define mpn_divrem_1 __MPN(divrem_1)
1479 __GMP_DECLSPEC mp_limb_t
mpn_divrem_1 (mp_ptr
, mp_size_t
, mp_srcptr
, mp_size_t
, mp_limb_t
);
1481 #define mpn_divrem_2 __MPN(divrem_2)
1482 __GMP_DECLSPEC mp_limb_t
mpn_divrem_2 (mp_ptr
, mp_size_t
, mp_ptr
, mp_size_t
, mp_srcptr
);
1484 #define mpn_div_qr_2 __MPN(div_qr_2)
1485 __GMP_DECLSPEC mp_limb_t
mpn_div_qr_2 (mp_ptr
, mp_ptr
, mp_srcptr
, mp_size_t
, mp_srcptr
);
1487 #define mpn_gcd __MPN(gcd)
1488 __GMP_DECLSPEC mp_size_t
mpn_gcd (mp_ptr
, mp_ptr
, mp_size_t
, mp_ptr
, mp_size_t
);
1490 #define mpn_gcd_1 __MPN(gcd_1)
1491 __GMP_DECLSPEC mp_limb_t
mpn_gcd_1 (mp_srcptr
, mp_size_t
, mp_limb_t
) __GMP_ATTRIBUTE_PURE
;
1493 #define mpn_gcdext_1 __MPN(gcdext_1)
1494 __GMP_DECLSPEC mp_limb_t
mpn_gcdext_1 (mp_limb_signed_t
*, mp_limb_signed_t
*, mp_limb_t
, mp_limb_t
);
1496 #define mpn_gcdext __MPN(gcdext)
1497 __GMP_DECLSPEC mp_size_t
mpn_gcdext (mp_ptr
, mp_ptr
, mp_size_t
*, mp_ptr
, mp_size_t
, mp_ptr
, mp_size_t
);
1499 #define mpn_get_str __MPN(get_str)
1500 __GMP_DECLSPEC
size_t mpn_get_str (unsigned char *, int, mp_ptr
, mp_size_t
);
1502 #define mpn_hamdist __MPN(hamdist)
1503 __GMP_DECLSPEC mp_bitcnt_t
mpn_hamdist (mp_srcptr
, mp_srcptr
, mp_size_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1505 #define mpn_lshift __MPN(lshift)
1506 __GMP_DECLSPEC mp_limb_t
mpn_lshift (mp_ptr
, mp_srcptr
, mp_size_t
, unsigned int);
1508 #define mpn_mod_1 __MPN(mod_1)
1509 __GMP_DECLSPEC mp_limb_t
mpn_mod_1 (mp_srcptr
, mp_size_t
, mp_limb_t
) __GMP_ATTRIBUTE_PURE
;
1511 #define mpn_mul __MPN(mul)
1512 __GMP_DECLSPEC mp_limb_t
mpn_mul (mp_ptr
, mp_srcptr
, mp_size_t
, mp_srcptr
, mp_size_t
);
1514 #define mpn_mul_1 __MPN(mul_1)
1515 __GMP_DECLSPEC mp_limb_t
mpn_mul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
);
1517 #define mpn_mul_n __MPN(mul_n)
1518 __GMP_DECLSPEC
void mpn_mul_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1520 #define mpn_sqr __MPN(sqr)
1521 __GMP_DECLSPEC
void mpn_sqr (mp_ptr
, mp_srcptr
, mp_size_t
);
1523 #define mpn_neg __MPN(neg)
1524 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_neg)
1525 __GMP_DECLSPEC mp_limb_t
mpn_neg (mp_ptr
, mp_srcptr
, mp_size_t
);
1528 #define mpn_com __MPN(com)
1529 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_com)
1530 __GMP_DECLSPEC
void mpn_com (mp_ptr
, mp_srcptr
, mp_size_t
);
1533 #define mpn_perfect_square_p __MPN(perfect_square_p)
1534 __GMP_DECLSPEC
int mpn_perfect_square_p (mp_srcptr
, mp_size_t
) __GMP_ATTRIBUTE_PURE
;
1536 #define mpn_perfect_power_p __MPN(perfect_power_p)
1537 __GMP_DECLSPEC
int mpn_perfect_power_p (mp_srcptr
, mp_size_t
) __GMP_ATTRIBUTE_PURE
;
1539 #define mpn_popcount __MPN(popcount)
1540 __GMP_DECLSPEC mp_bitcnt_t
mpn_popcount (mp_srcptr
, mp_size_t
) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE
;
1542 #define mpn_pow_1 __MPN(pow_1)
1543 __GMP_DECLSPEC mp_size_t
mpn_pow_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
, mp_ptr
);
1545 /* undocumented now, but retained here for upward compatibility */
1546 #define mpn_preinv_mod_1 __MPN(preinv_mod_1)
1547 __GMP_DECLSPEC mp_limb_t
mpn_preinv_mod_1 (mp_srcptr
, mp_size_t
, mp_limb_t
, mp_limb_t
) __GMP_ATTRIBUTE_PURE
;
1549 #define mpn_random __MPN(random)
1550 __GMP_DECLSPEC
void mpn_random (mp_ptr
, mp_size_t
);
1552 #define mpn_random2 __MPN(random2)
1553 __GMP_DECLSPEC
void mpn_random2 (mp_ptr
, mp_size_t
);
1555 #define mpn_rshift __MPN(rshift)
1556 __GMP_DECLSPEC mp_limb_t
mpn_rshift (mp_ptr
, mp_srcptr
, mp_size_t
, unsigned int);
1558 #define mpn_scan0 __MPN(scan0)
1559 __GMP_DECLSPEC mp_bitcnt_t
mpn_scan0 (mp_srcptr
, mp_bitcnt_t
) __GMP_ATTRIBUTE_PURE
;
1561 #define mpn_scan1 __MPN(scan1)
1562 __GMP_DECLSPEC mp_bitcnt_t
mpn_scan1 (mp_srcptr
, mp_bitcnt_t
) __GMP_ATTRIBUTE_PURE
;
1564 #define mpn_set_str __MPN(set_str)
1565 __GMP_DECLSPEC mp_size_t
mpn_set_str (mp_ptr
, const unsigned char *, size_t, int);
1567 #define mpn_sqrtrem __MPN(sqrtrem)
1568 __GMP_DECLSPEC mp_size_t
mpn_sqrtrem (mp_ptr
, mp_ptr
, mp_srcptr
, mp_size_t
);
1570 #define mpn_sub __MPN(sub)
1571 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub)
1572 __GMP_DECLSPEC mp_limb_t
mpn_sub (mp_ptr
, mp_srcptr
, mp_size_t
, mp_srcptr
, mp_size_t
);
1575 #define mpn_sub_1 __MPN(sub_1)
1576 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1)
1577 __GMP_DECLSPEC mp_limb_t
mpn_sub_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
) __GMP_NOTHROW
;
1580 #define mpn_sub_n __MPN(sub_n)
1581 __GMP_DECLSPEC mp_limb_t
mpn_sub_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1583 #define mpn_submul_1 __MPN(submul_1)
1584 __GMP_DECLSPEC mp_limb_t
mpn_submul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
);
1586 #define mpn_tdiv_qr __MPN(tdiv_qr)
1587 __GMP_DECLSPEC
void mpn_tdiv_qr (mp_ptr
, mp_ptr
, mp_size_t
, mp_srcptr
, mp_size_t
, mp_srcptr
, mp_size_t
);
1589 #define mpn_and_n __MPN(and_n)
1590 __GMP_DECLSPEC
void mpn_and_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1591 #define mpn_andn_n __MPN(andn_n)
1592 __GMP_DECLSPEC
void mpn_andn_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1593 #define mpn_nand_n __MPN(nand_n)
1594 __GMP_DECLSPEC
void mpn_nand_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1595 #define mpn_ior_n __MPN(ior_n)
1596 __GMP_DECLSPEC
void mpn_ior_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1597 #define mpn_iorn_n __MPN(iorn_n)
1598 __GMP_DECLSPEC
void mpn_iorn_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1599 #define mpn_nior_n __MPN(nior_n)
1600 __GMP_DECLSPEC
void mpn_nior_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1601 #define mpn_xor_n __MPN(xor_n)
1602 __GMP_DECLSPEC
void mpn_xor_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1603 #define mpn_xnor_n __MPN(xnor_n)
1604 __GMP_DECLSPEC
void mpn_xnor_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
);
1606 #define mpn_copyi __MPN(copyi)
1607 __GMP_DECLSPEC
void mpn_copyi (mp_ptr
, mp_srcptr
, mp_size_t
);
1608 #define mpn_copyd __MPN(copyd)
1609 __GMP_DECLSPEC
void mpn_copyd (mp_ptr
, mp_srcptr
, mp_size_t
);
1610 #define mpn_zero __MPN(zero)
1611 __GMP_DECLSPEC
void mpn_zero (mp_ptr
, mp_size_t
);
1613 /**************** mpz inlines ****************/
1615 /* The following are provided as inlines where possible, but always exist as
1616 library functions too, for binary compatibility.
1618 Within gmp itself this inlining generally isn't relied on, since it
1619 doesn't get done for all compilers, whereas if something is worth
1620 inlining then it's worth arranging always.
1622 There are two styles of inlining here. When the same bit of code is
1623 wanted for the inline as for the library version, then __GMP_FORCE_foo
1624 arranges for that code to be emitted and the __GMP_EXTERN_INLINE
1625 directive suppressed, eg. mpz_fits_uint_p. When a different bit of code
1626 is wanted for the inline than for the library version, then
1627 __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */
1629 #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs)
1630 __GMP_EXTERN_INLINE
void
1631 mpz_abs (mpz_ptr __gmp_w
, mpz_srcptr __gmp_u
)
1633 if (__gmp_w
!= __gmp_u
)
1634 mpz_set (__gmp_w
, __gmp_u
);
1635 __gmp_w
->_mp_size
= __GMP_ABS (__gmp_w
->_mp_size
);
1639 #if GMP_NAIL_BITS == 0
1640 #define __GMPZ_FITS_UTYPE_P(z,maxval) \
1641 mp_size_t __gmp_n = z->_mp_size; \
1642 mp_ptr __gmp_p = z->_mp_d; \
1643 return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval));
1645 #define __GMPZ_FITS_UTYPE_P(z,maxval) \
1646 mp_size_t __gmp_n = z->_mp_size; \
1647 mp_ptr __gmp_p = z->_mp_d; \
1648 return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \
1649 || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS)));
1652 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p)
1653 #if ! defined (__GMP_FORCE_mpz_fits_uint_p)
1657 mpz_fits_uint_p (mpz_srcptr __gmp_z
) __GMP_NOTHROW
1659 __GMPZ_FITS_UTYPE_P (__gmp_z
, __GMP_UINT_MAX
);
1663 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p)
1664 #if ! defined (__GMP_FORCE_mpz_fits_ulong_p)
1668 mpz_fits_ulong_p (mpz_srcptr __gmp_z
) __GMP_NOTHROW
1670 __GMPZ_FITS_UTYPE_P (__gmp_z
, __GMP_ULONG_MAX
);
1674 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p)
1675 #if ! defined (__GMP_FORCE_mpz_fits_ushort_p)
1679 mpz_fits_ushort_p (mpz_srcptr __gmp_z
) __GMP_NOTHROW
1681 __GMPZ_FITS_UTYPE_P (__gmp_z
, __GMP_USHRT_MAX
);
1685 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui)
1686 #if ! defined (__GMP_FORCE_mpz_get_ui)
1690 mpz_get_ui (mpz_srcptr __gmp_z
) __GMP_NOTHROW
1692 mp_ptr __gmp_p
= __gmp_z
->_mp_d
;
1693 mp_size_t __gmp_n
= __gmp_z
->_mp_size
;
1694 mp_limb_t __gmp_l
= __gmp_p
[0];
1695 /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings
1696 about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland
1697 C++ 6.0 warnings about condition always true for something like
1698 "__GMP_ULONG_MAX < GMP_NUMB_MASK". */
1699 #if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB)
1700 /* limb==long and no nails, or limb==longlong, one limb is enough */
1701 return (__gmp_n
!= 0 ? __gmp_l
: 0);
1703 /* limb==long and nails, need two limbs when available */
1704 __gmp_n
= __GMP_ABS (__gmp_n
);
1706 return (__gmp_n
!= 0 ? __gmp_l
: 0);
1708 return __gmp_l
+ (__gmp_p
[1] << GMP_NUMB_BITS
);
1713 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn)
1714 #if ! defined (__GMP_FORCE_mpz_getlimbn)
1718 mpz_getlimbn (mpz_srcptr __gmp_z
, mp_size_t __gmp_n
) __GMP_NOTHROW
1720 mp_limb_t __gmp_result
= 0;
1721 if (__GMP_LIKELY (__gmp_n
>= 0 && __gmp_n
< __GMP_ABS (__gmp_z
->_mp_size
)))
1722 __gmp_result
= __gmp_z
->_mp_d
[__gmp_n
];
1723 return __gmp_result
;
1727 #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg)
1728 __GMP_EXTERN_INLINE
void
1729 mpz_neg (mpz_ptr __gmp_w
, mpz_srcptr __gmp_u
)
1731 if (__gmp_w
!= __gmp_u
)
1732 mpz_set (__gmp_w
, __gmp_u
);
1733 __gmp_w
->_mp_size
= - __gmp_w
->_mp_size
;
1737 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p)
1738 #if ! defined (__GMP_FORCE_mpz_perfect_square_p)
1742 mpz_perfect_square_p (mpz_srcptr __gmp_a
)
1744 mp_size_t __gmp_asize
;
1747 __gmp_asize
= __gmp_a
->_mp_size
;
1748 __gmp_result
= (__gmp_asize
>= 0); /* zero is a square, negatives are not */
1749 if (__GMP_LIKELY (__gmp_asize
> 0))
1750 __gmp_result
= mpn_perfect_square_p (__gmp_a
->_mp_d
, __gmp_asize
);
1751 return __gmp_result
;
1755 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount)
1756 #if ! defined (__GMP_FORCE_mpz_popcount)
1760 mpz_popcount (mpz_srcptr __gmp_u
) __GMP_NOTHROW
1762 mp_size_t __gmp_usize
;
1763 mp_bitcnt_t __gmp_result
;
1765 __gmp_usize
= __gmp_u
->_mp_size
;
1766 __gmp_result
= (__gmp_usize
< 0 ? __GMP_ULONG_MAX
: 0);
1767 if (__GMP_LIKELY (__gmp_usize
> 0))
1768 __gmp_result
= mpn_popcount (__gmp_u
->_mp_d
, __gmp_usize
);
1769 return __gmp_result
;
1773 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q)
1774 #if ! defined (__GMP_FORCE_mpz_set_q)
1778 mpz_set_q (mpz_ptr __gmp_w
, mpq_srcptr __gmp_u
)
1780 mpz_tdiv_q (__gmp_w
, mpq_numref (__gmp_u
), mpq_denref (__gmp_u
));
1784 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size)
1785 #if ! defined (__GMP_FORCE_mpz_size)
1789 mpz_size (mpz_srcptr __gmp_z
) __GMP_NOTHROW
1791 return __GMP_ABS (__gmp_z
->_mp_size
);
1796 /**************** mpq inlines ****************/
1798 #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs)
1799 __GMP_EXTERN_INLINE
void
1800 mpq_abs (mpq_ptr __gmp_w
, mpq_srcptr __gmp_u
)
1802 if (__gmp_w
!= __gmp_u
)
1803 mpq_set (__gmp_w
, __gmp_u
);
1804 __gmp_w
->_mp_num
._mp_size
= __GMP_ABS (__gmp_w
->_mp_num
._mp_size
);
1808 #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg)
1809 __GMP_EXTERN_INLINE
void
1810 mpq_neg (mpq_ptr __gmp_w
, mpq_srcptr __gmp_u
)
1812 if (__gmp_w
!= __gmp_u
)
1813 mpq_set (__gmp_w
, __gmp_u
);
1814 __gmp_w
->_mp_num
._mp_size
= - __gmp_w
->_mp_num
._mp_size
;
1819 /**************** mpn inlines ****************/
1821 /* The comments with __GMPN_ADD_1 below apply here too.
1823 The test for FUNCTION returning 0 should predict well. If it's assumed
1824 {yp,ysize} will usually have a random number of bits then the high limb
1825 won't be full and a carry out will occur a good deal less than 50% of the
1828 ysize==0 isn't a documented feature, but is used internally in a few
1831 Producing cout last stops it using up a register during the main part of
1832 the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))"
1833 doesn't seem able to move the true and false legs of the conditional up
1834 to the two places cout is generated. */
1836 #define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \
1838 mp_size_t __gmp_i; \
1839 mp_limb_t __gmp_x; \
1841 /* ASSERT ((ysize) >= 0); */ \
1842 /* ASSERT ((xsize) >= (ysize)); */ \
1843 /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \
1844 /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \
1846 __gmp_i = (ysize); \
1849 if (FUNCTION (wp, xp, yp, __gmp_i)) \
1853 if (__gmp_i >= (xsize)) \
1858 __gmp_x = (xp)[__gmp_i]; \
1864 __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \
1870 #define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \
1871 __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \
1872 (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0))
1873 #define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \
1874 __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \
1875 (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0))
1878 /* The use of __gmp_i indexing is designed to ensure a compile time src==dst
1879 remains nice and clear to the compiler, so that __GMPN_COPY_REST can
1880 disappear, and the load/add/store gets a chance to become a
1881 read-modify-write on CISC CPUs.
1885 Using a pair of pointers instead of indexing would be possible, but gcc
1886 isn't able to recognise compile-time src==dst in that case, even when the
1887 pointers are incremented more or less together. Other compilers would
1888 very likely have similar difficulty.
1890 gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or
1891 similar to detect a compile-time src==dst. This works nicely on gcc
1892 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems
1893 to be always false, for a pointer p. But the current code form seems
1894 good enough for src==dst anyway.
1896 gcc on x86 as usual doesn't give particularly good flags handling for the
1897 carry/borrow detection. It's tempting to want some multi instruction asm
1898 blocks to help it, and this was tried, but in truth there's only a few
1899 instructions to save and any gain is all too easily lost by register
1900 juggling setting up for the asm. */
1902 #if GMP_NAIL_BITS == 0
1903 #define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \
1905 mp_size_t __gmp_i; \
1906 mp_limb_t __gmp_x, __gmp_r; \
1908 /* ASSERT ((n) >= 1); */ \
1909 /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \
1911 __gmp_x = (src)[0]; \
1912 __gmp_r = __gmp_x OP (v); \
1913 (dst)[0] = __gmp_r; \
1914 if (CB (__gmp_r, __gmp_x, (v))) \
1917 for (__gmp_i = 1; __gmp_i < (n);) \
1919 __gmp_x = (src)[__gmp_i]; \
1920 __gmp_r = __gmp_x OP 1; \
1921 (dst)[__gmp_i] = __gmp_r; \
1923 if (!CB (__gmp_r, __gmp_x, 1)) \
1925 if ((src) != (dst)) \
1926 __GMPN_COPY_REST (dst, src, n, __gmp_i); \
1934 if ((src) != (dst)) \
1935 __GMPN_COPY_REST (dst, src, n, 1); \
1941 #if GMP_NAIL_BITS >= 1
1942 #define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \
1944 mp_size_t __gmp_i; \
1945 mp_limb_t __gmp_x, __gmp_r; \
1947 /* ASSERT ((n) >= 1); */ \
1948 /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \
1950 __gmp_x = (src)[0]; \
1951 __gmp_r = __gmp_x OP (v); \
1952 (dst)[0] = __gmp_r & GMP_NUMB_MASK; \
1953 if (__gmp_r >> GMP_NUMB_BITS != 0) \
1956 for (__gmp_i = 1; __gmp_i < (n);) \
1958 __gmp_x = (src)[__gmp_i]; \
1959 __gmp_r = __gmp_x OP 1; \
1960 (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \
1962 if (__gmp_r >> GMP_NUMB_BITS == 0) \
1964 if ((src) != (dst)) \
1965 __GMPN_COPY_REST (dst, src, n, __gmp_i); \
1973 if ((src) != (dst)) \
1974 __GMPN_COPY_REST (dst, src, n, 1); \
1980 #define __GMPN_ADDCB(r,x,y) ((r) < (y))
1981 #define __GMPN_SUBCB(r,x,y) ((x) < (y))
1983 #define __GMPN_ADD_1(cout, dst, src, n, v) \
1984 __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB)
1985 #define __GMPN_SUB_1(cout, dst, src, n, v) \
1986 __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB)
1989 /* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or
1990 negative. size==0 is allowed. On random data usually only one limb will
1991 need to be examined to get a result, so it's worth having it inline. */
1992 #define __GMPN_CMP(result, xp, yp, size) \
1994 mp_size_t __gmp_i; \
1995 mp_limb_t __gmp_x, __gmp_y; \
1997 /* ASSERT ((size) >= 0); */ \
2001 while (--__gmp_i >= 0) \
2003 __gmp_x = (xp)[__gmp_i]; \
2004 __gmp_y = (yp)[__gmp_i]; \
2005 if (__gmp_x != __gmp_y) \
2007 /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \
2008 (result) = (__gmp_x > __gmp_y ? 1 : -1); \
2015 #if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST)
2016 #define __GMPN_COPY_REST(dst, src, size, start) \
2018 /* ASSERT ((start) >= 0); */ \
2019 /* ASSERT ((start) <= (size)); */ \
2020 __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \
2024 /* Copy {src,size} to {dst,size}, starting at "start". This is designed to
2025 keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1,
2027 #if ! defined (__GMPN_COPY_REST)
2028 #define __GMPN_COPY_REST(dst, src, size, start) \
2030 mp_size_t __gmp_j; \
2031 /* ASSERT ((size) >= 0); */ \
2032 /* ASSERT ((start) >= 0); */ \
2033 /* ASSERT ((start) <= (size)); */ \
2034 /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \
2035 __GMP_CRAY_Pragma ("_CRI ivdep"); \
2036 for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \
2037 (dst)[__gmp_j] = (src)[__gmp_j]; \
2041 /* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use
2042 mpn_copyi if there's a native version, and if we don't mind demanding
2043 binary compatibility for it (on targets which use it). */
2045 #if ! defined (__GMPN_COPY)
2046 #define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0)
2050 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add)
2051 #if ! defined (__GMP_FORCE_mpn_add)
2055 mpn_add (mp_ptr __gmp_wp
, mp_srcptr __gmp_xp
, mp_size_t __gmp_xsize
, mp_srcptr __gmp_yp
, mp_size_t __gmp_ysize
)
2058 __GMPN_ADD (__gmp_c
, __gmp_wp
, __gmp_xp
, __gmp_xsize
, __gmp_yp
, __gmp_ysize
);
2063 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1)
2064 #if ! defined (__GMP_FORCE_mpn_add_1)
2068 mpn_add_1 (mp_ptr __gmp_dst
, mp_srcptr __gmp_src
, mp_size_t __gmp_size
, mp_limb_t __gmp_n
) __GMP_NOTHROW
2071 __GMPN_ADD_1 (__gmp_c
, __gmp_dst
, __gmp_src
, __gmp_size
, __gmp_n
);
2076 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp)
2077 #if ! defined (__GMP_FORCE_mpn_cmp)
2081 mpn_cmp (mp_srcptr __gmp_xp
, mp_srcptr __gmp_yp
, mp_size_t __gmp_size
) __GMP_NOTHROW
2084 __GMPN_CMP (__gmp_result
, __gmp_xp
, __gmp_yp
, __gmp_size
);
2085 return __gmp_result
;
2089 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub)
2090 #if ! defined (__GMP_FORCE_mpn_sub)
2094 mpn_sub (mp_ptr __gmp_wp
, mp_srcptr __gmp_xp
, mp_size_t __gmp_xsize
, mp_srcptr __gmp_yp
, mp_size_t __gmp_ysize
)
2097 __GMPN_SUB (__gmp_c
, __gmp_wp
, __gmp_xp
, __gmp_xsize
, __gmp_yp
, __gmp_ysize
);
2102 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1)
2103 #if ! defined (__GMP_FORCE_mpn_sub_1)
2107 mpn_sub_1 (mp_ptr __gmp_dst
, mp_srcptr __gmp_src
, mp_size_t __gmp_size
, mp_limb_t __gmp_n
) __GMP_NOTHROW
2110 __GMPN_SUB_1 (__gmp_c
, __gmp_dst
, __gmp_src
, __gmp_size
, __gmp_n
);
2115 #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_neg)
2116 #if ! defined (__GMP_FORCE_mpn_neg)
2120 mpn_neg (mp_ptr __gmp_rp
, mp_srcptr __gmp_up
, mp_size_t __gmp_n
)
2122 mp_limb_t __gmp_ul
, __gmp_cy
;
2125 __gmp_ul
= *__gmp_up
++;
2126 *__gmp_rp
++ = -__gmp_ul
- __gmp_cy
;
2127 __gmp_cy
|= __gmp_ul
!= 0;
2128 } while (--__gmp_n
!= 0);
2133 #if defined (__cplusplus)
2138 /* Allow faster testing for negative, zero, and positive. */
2139 #define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
2140 #define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
2141 #define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
2143 /* When using GCC, optimize certain common comparisons. */
2144 #if defined (__GNUC__) && __GNUC__ >= 2
2145 #define mpz_cmp_ui(Z,UI) \
2146 (__builtin_constant_p (UI) && (UI) == 0 \
2147 ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI))
2148 #define mpz_cmp_si(Z,SI) \
2149 (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z) \
2150 : __builtin_constant_p (SI) && (SI) > 0 \
2151 ? _mpz_cmp_ui (Z, __GMP_CAST (unsigned long int, SI)) \
2152 : _mpz_cmp_si (Z,SI))
2153 #define mpq_cmp_ui(Q,NUI,DUI) \
2154 (__builtin_constant_p (NUI) && (NUI) == 0 \
2155 ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI))
2156 #define mpq_cmp_si(q,n,d) \
2157 (__builtin_constant_p ((n) >= 0) && (n) >= 0 \
2158 ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \
2159 : _mpq_cmp_si (q, n, d))
2161 #define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI)
2162 #define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI)
2163 #define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI)
2164 #define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d)
2168 /* Using "&" rather than "&&" means these can come out branch-free. Every
2169 mpz_t has at least one limb allocated, so fetching the low limb is always
2171 #define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0]))
2172 #define mpz_even_p(z) (! mpz_odd_p (z))
2175 /**************** C++ routines ****************/
2178 __GMP_DECLSPEC_XX
std::ostream
& operator<< (std::ostream
&, mpz_srcptr
);
2179 __GMP_DECLSPEC_XX
std::ostream
& operator<< (std::ostream
&, mpq_srcptr
);
2180 __GMP_DECLSPEC_XX
std::ostream
& operator<< (std::ostream
&, mpf_srcptr
);
2181 __GMP_DECLSPEC_XX
std::istream
& operator>> (std::istream
&, mpz_ptr
);
2182 __GMP_DECLSPEC_XX
std::istream
& operator>> (std::istream
&, mpq_ptr
);
2183 __GMP_DECLSPEC_XX
std::istream
& operator>> (std::istream
&, mpf_ptr
);
2187 /* Source-level compatibility with GMP 2 and earlier. */
2188 #define mpn_divmod(qp,np,nsize,dp,dsize) \
2189 mpn_divrem (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dp, dsize)
2191 /* Source-level compatibility with GMP 1. */
2192 #define mpz_mdiv mpz_fdiv_q
2193 #define mpz_mdivmod mpz_fdiv_qr
2194 #define mpz_mmod mpz_fdiv_r
2195 #define mpz_mdiv_ui mpz_fdiv_q_ui
2196 #define mpz_mdivmod_ui(q,r,n,d) \
2197 (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
2198 #define mpz_mmod_ui(r,n,d) \
2199 (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
2201 /* Useful synonyms, but not quite compatible with GMP 1. */
2202 #define mpz_div mpz_fdiv_q
2203 #define mpz_divmod mpz_fdiv_qr
2204 #define mpz_div_ui mpz_fdiv_q_ui
2205 #define mpz_divmod_ui mpz_fdiv_qr_ui
2206 #define mpz_div_2exp mpz_fdiv_q_2exp
2207 #define mpz_mod_2exp mpz_fdiv_r_2exp
2212 GMP_ERROR_UNSUPPORTED_ARGUMENT
= 1,
2213 GMP_ERROR_DIVISION_BY_ZERO
= 2,
2214 GMP_ERROR_SQRT_OF_NEGATIVE
= 4,
2215 GMP_ERROR_INVALID_ARGUMENT
= 8
2218 /* Define CC and CFLAGS which were used to build this version of GMP */
2219 #define __GMP_CC "gcc -std=gnu99"
2220 #define __GMP_CFLAGS "-m32 -O2 -pedantic -mcpu=v7"
2222 /* Major version number is the value of __GNU_MP__ too, above and in mp.h. */
2223 #define __GNU_MP_VERSION 5
2224 #define __GNU_MP_VERSION_MINOR 1
2225 #define __GNU_MP_VERSION_PATCHLEVEL 3
2226 #define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL)
2229 #endif /* __GMP_H__ */