gmp.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336
  1. /* Definitions for GNU multiple precision functions. -*- mode: c -*-
  2. Copyright 1991, 1993-1997, 1999-2016, 2020 Free Software Foundation, Inc.
  3. This file is part of the GNU MP Library.
  4. The GNU MP Library is free software; you can redistribute it and/or modify
  5. it under the terms of either:
  6. * the GNU Lesser General Public License as published by the Free
  7. Software Foundation; either version 3 of the License, or (at your
  8. option) any later version.
  9. or
  10. * the GNU General Public License as published by the Free Software
  11. Foundation; either version 2 of the License, or (at your option) any
  12. later version.
  13. or both in parallel, as here.
  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 General Public License
  17. for more details.
  18. You should have received copies of the GNU General Public License and the
  19. GNU Lesser General Public License along with the GNU MP Library. If not,
  20. see https://www.gnu.org/licenses/. */
  21. #ifndef __GMP_H__
  22. #if defined (__cplusplus)
  23. #include <iosfwd> /* for std::istream, std::ostream, std::string */
  24. #include <cstdio>
  25. #endif
  26. /* Instantiated by configure. */
  27. #if ! defined (__GMP_WITHIN_CONFIGURE)
  28. #define __GMP_HAVE_HOST_CPU_FAMILY_power 0
  29. #define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0
  30. #define GMP_LIMB_BITS 64
  31. #define GMP_NAIL_BITS 0
  32. #endif
  33. #define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS)
  34. #define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS)
  35. #define GMP_NUMB_MAX GMP_NUMB_MASK
  36. #define GMP_NAIL_MASK (~ GMP_NUMB_MASK)
  37. #ifndef __GNU_MP__
  38. #define __GNU_MP__ 6
  39. #include <stddef.h> /* for size_t */
  40. #include <limits.h>
  41. /* Instantiated by configure. */
  42. #if ! defined (__GMP_WITHIN_CONFIGURE)
  43. #define _LONG_LONG_LIMB 1
  44. #define __GMP_LIBGMP_DLL 0
  45. #endif
  46. /* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in
  47. all other circumstances.
  48. When compiling objects for libgmp, __GMP_DECLSPEC is an export directive,
  49. or when compiling for an application it's an import directive. The two
  50. cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles
  51. (and not defined from an application).
  52. __GMP_DECLSPEC_XX is similarly used for libgmpxx. __GMP_WITHIN_GMPXX
  53. indicates when building libgmpxx, and in that case libgmpxx functions are
  54. exports, but libgmp functions which might get called are imports.
  55. Libtool DLL_EXPORT define is not used.
  56. There's no attempt to support GMP built both static and DLL. Doing so
  57. would mean applications would have to tell us which of the two is going
  58. to be used when linking, and that seems very tedious and error prone if
  59. using GMP by hand, and equally tedious from a package since autoconf and
  60. automake don't give much help.
  61. __GMP_DECLSPEC is required on all documented global functions and
  62. variables, the various internals in gmp-impl.h etc can be left unadorned.
  63. But internals used by the test programs or speed measuring programs
  64. should have __GMP_DECLSPEC, and certainly constants or variables must
  65. have it or the wrong address will be resolved.
  66. In gcc __declspec can go at either the start or end of a prototype.
  67. In Microsoft C __declspec must go at the start, or after the type like
  68. void __declspec(...) *foo()". There's no __dllexport or anything to
  69. guard against someone foolish #defining dllexport. _export used to be
  70. available, but no longer.
  71. In Borland C _export still exists, but needs to go after the type, like
  72. "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to
  73. make use of that. Probably more trouble than it's worth. */
  74. #if defined (__GNUC__)
  75. #define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__)
  76. #define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__)
  77. #endif
  78. #if defined (_MSC_VER) || defined (__BORLANDC__)
  79. #define __GMP_DECLSPEC_EXPORT __declspec(dllexport)
  80. #define __GMP_DECLSPEC_IMPORT __declspec(dllimport)
  81. #endif
  82. #ifdef __WATCOMC__
  83. #define __GMP_DECLSPEC_EXPORT __export
  84. #define __GMP_DECLSPEC_IMPORT __import
  85. #endif
  86. #ifdef __IBMC__
  87. #define __GMP_DECLSPEC_EXPORT _Export
  88. #define __GMP_DECLSPEC_IMPORT _Import
  89. #endif
  90. #if __GMP_LIBGMP_DLL
  91. #ifdef __GMP_WITHIN_GMP
  92. /* compiling to go into a DLL libgmp */
  93. #define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT
  94. #else
  95. /* compiling to go into an application which will link to a DLL libgmp */
  96. #define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT
  97. #endif
  98. #else
  99. /* all other cases */
  100. #define __GMP_DECLSPEC
  101. #endif
  102. #ifdef __GMP_SHORT_LIMB
  103. typedef unsigned int mp_limb_t;
  104. typedef int mp_limb_signed_t;
  105. #else
  106. #ifdef _LONG_LONG_LIMB
  107. typedef unsigned long long int mp_limb_t;
  108. typedef long long int mp_limb_signed_t;
  109. #else
  110. typedef unsigned long int mp_limb_t;
  111. typedef long int mp_limb_signed_t;
  112. #endif
  113. #endif
  114. typedef unsigned long int mp_bitcnt_t;
  115. /* For reference, note that the name __mpz_struct gets into C++ mangled
  116. function names, which means although the "__" suggests an internal, we
  117. must leave this name for binary compatibility. */
  118. typedef struct
  119. {
  120. int _mp_alloc; /* Number of *limbs* allocated and pointed
  121. to by the _mp_d field. */
  122. int _mp_size; /* abs(_mp_size) is the number of limbs the
  123. last field points to. If _mp_size is
  124. negative this is a negative number. */
  125. mp_limb_t *_mp_d; /* Pointer to the limbs. */
  126. } __mpz_struct;
  127. #endif /* __GNU_MP__ */
  128. typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */
  129. typedef __mpz_struct mpz_t[1];
  130. typedef mp_limb_t * mp_ptr;
  131. typedef const mp_limb_t * mp_srcptr;
  132. #if defined (_CRAY) && ! defined (_CRAYMPP)
  133. /* plain `int' is much faster (48 bits) */
  134. #define __GMP_MP_SIZE_T_INT 1
  135. typedef int mp_size_t;
  136. typedef int mp_exp_t;
  137. #else
  138. #define __GMP_MP_SIZE_T_INT 0
  139. typedef long int mp_size_t;
  140. typedef long int mp_exp_t;
  141. #endif
  142. typedef struct
  143. {
  144. __mpz_struct _mp_num;
  145. __mpz_struct _mp_den;
  146. } __mpq_struct;
  147. typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */
  148. typedef __mpq_struct mpq_t[1];
  149. typedef struct
  150. {
  151. int _mp_prec; /* Max precision, in number of `mp_limb_t's.
  152. Set by mpf_init and modified by
  153. mpf_set_prec. The area pointed to by the
  154. _mp_d field contains `prec' + 1 limbs. */
  155. int _mp_size; /* abs(_mp_size) is the number of limbs the
  156. last field points to. If _mp_size is
  157. negative this is a negative number. */
  158. mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */
  159. mp_limb_t *_mp_d; /* Pointer to the limbs. */
  160. } __mpf_struct;
  161. /* typedef __mpf_struct MP_FLOAT; */
  162. typedef __mpf_struct mpf_t[1];
  163. /* Available random number generation algorithms. */
  164. typedef enum
  165. {
  166. GMP_RAND_ALG_DEFAULT = 0,
  167. GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */
  168. } gmp_randalg_t;
  169. /* Random state struct. */
  170. typedef struct
  171. {
  172. mpz_t _mp_seed; /* _mp_d member points to state of the generator. */
  173. gmp_randalg_t _mp_alg; /* Currently unused. */
  174. union {
  175. void *_mp_lc; /* Pointer to function pointers structure. */
  176. } _mp_algdata;
  177. } __gmp_randstate_struct;
  178. typedef __gmp_randstate_struct gmp_randstate_t[1];
  179. /* Types for function declarations in gmp files. */
  180. /* ??? Should not pollute user name space with these ??? */
  181. typedef const __mpz_struct *mpz_srcptr;
  182. typedef __mpz_struct *mpz_ptr;
  183. typedef const __mpf_struct *mpf_srcptr;
  184. typedef __mpf_struct *mpf_ptr;
  185. typedef const __mpq_struct *mpq_srcptr;
  186. typedef __mpq_struct *mpq_ptr;
  187. #if __GMP_LIBGMP_DLL
  188. #ifdef __GMP_WITHIN_GMPXX
  189. /* compiling to go into a DLL libgmpxx */
  190. #define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT
  191. #else
  192. /* compiling to go into a application which will link to a DLL libgmpxx */
  193. #define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT
  194. #endif
  195. #else
  196. /* all other cases */
  197. #define __GMP_DECLSPEC_XX
  198. #endif
  199. #ifndef __MPN
  200. #define __MPN(x) __gmpn_##x
  201. #endif
  202. /* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
  203. <iostream> defines EOF but not FILE. */
  204. #if defined (FILE) \
  205. || defined (H_STDIO) \
  206. || defined (_H_STDIO) /* AIX */ \
  207. || defined (_STDIO_H) /* glibc, Sun, SCO */ \
  208. || defined (_STDIO_H_) /* BSD, OSF */ \
  209. || defined (__STDIO_H) /* Borland */ \
  210. || defined (__STDIO_H__) /* IRIX */ \
  211. || defined (_STDIO_INCLUDED) /* HPUX */ \
  212. || defined (__dj_include_stdio_h_) /* DJGPP */ \
  213. || defined (_FILE_DEFINED) /* Microsoft */ \
  214. || defined (__STDIO__) /* Apple MPW MrC */ \
  215. || defined (_MSL_STDIO_H) /* Metrowerks */ \
  216. || defined (_STDIO_H_INCLUDED) /* QNX4 */ \
  217. || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
  218. || defined (__STDIO_LOADED) /* VMS */ \
  219. || defined (__DEFINED_FILE) /* musl */
  220. #define _GMP_H_HAVE_FILE 1
  221. #endif
  222. /* In ISO C, if a prototype involving "struct obstack *" is given without
  223. that structure defined, then the struct is scoped down to just the
  224. prototype, causing a conflict if it's subsequently defined for real. So
  225. only give prototypes if we've got obstack.h. */
  226. #if defined (_OBSTACK_H) /* glibc <obstack.h> */
  227. #define _GMP_H_HAVE_OBSTACK 1
  228. #endif
  229. /* The prototypes for gmp_vprintf etc are provided only if va_list is defined,
  230. via an application having included <stdarg.h>. Usually va_list is a typedef
  231. so can't be tested directly, but C99 specifies that va_start is a macro.
  232. <stdio.h> will define some sort of va_list for vprintf and vfprintf, but
  233. let's not bother trying to use that since it's not standard and since
  234. application uses for gmp_vprintf etc will almost certainly require the
  235. whole <stdarg.h> anyway. */
  236. #ifdef va_start
  237. #define _GMP_H_HAVE_VA_LIST 1
  238. #endif
  239. /* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */
  240. #if defined (__GNUC__) && defined (__GNUC_MINOR__)
  241. #define __GMP_GNUC_PREREQ(maj, min) \
  242. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  243. #else
  244. #define __GMP_GNUC_PREREQ(maj, min) 0
  245. #endif
  246. /* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically
  247. it means a function does nothing but examine its arguments and memory
  248. (global or via arguments) to generate a return value, but changes nothing
  249. and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets
  250. tune/common.c etc turn this off when trying to write timing loops. */
  251. #if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE)
  252. #define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__))
  253. #else
  254. #define __GMP_ATTRIBUTE_PURE
  255. #endif
  256. /* __GMP_CAST allows us to use static_cast in C++, so our macros are clean
  257. to "g++ -Wold-style-cast".
  258. Casts in "extern inline" code within an extern "C" block don't induce
  259. these warnings, so __GMP_CAST only needs to be used on documented
  260. macros. */
  261. #ifdef __cplusplus
  262. #define __GMP_CAST(type, expr) (static_cast<type> (expr))
  263. #else
  264. #define __GMP_CAST(type, expr) ((type) (expr))
  265. #endif
  266. /* An empty "throw ()" means the function doesn't throw any C++ exceptions,
  267. this can save some stack frame info in applications.
  268. Currently it's given only on functions which never divide-by-zero etc,
  269. don't allocate memory, and are expected to never need to allocate memory.
  270. This leaves open the possibility of a C++ throw from a future GMP
  271. exceptions scheme.
  272. mpz_set_ui etc are omitted to leave open the lazy allocation scheme
  273. described in doc/tasks.html. mpz_get_d etc are omitted to leave open
  274. exceptions for float overflows.
  275. Note that __GMP_NOTHROW must be given on any inlines the same as on their
  276. prototypes (for g++ at least, where they're used together). Note also
  277. that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like
  278. __GMP_ATTRIBUTE_PURE. */
  279. #if defined (__cplusplus)
  280. #if __cplusplus >= 201103L
  281. #define __GMP_NOTHROW noexcept
  282. #else
  283. #define __GMP_NOTHROW throw ()
  284. #endif
  285. #else
  286. #define __GMP_NOTHROW
  287. #endif
  288. /* PORTME: What other compilers have a useful "extern inline"? "static
  289. inline" would be an acceptable substitute if the compiler (or linker)
  290. discards unused statics. */
  291. /* gcc has __inline__ in all modes, including strict ansi. Give a prototype
  292. for an inline too, so as to correctly specify "dllimport" on windows, in
  293. case the function is called rather than inlined.
  294. GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
  295. inline semantics, unless -fgnu89-inline is used. */
  296. #ifdef __GNUC__
  297. #if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2) \
  298. || (defined __GNUC_GNU_INLINE__ && defined __cplusplus)
  299. #define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__))
  300. #else
  301. #define __GMP_EXTERN_INLINE extern __inline__
  302. #endif
  303. #define __GMP_INLINE_PROTOTYPES 1
  304. #endif
  305. /* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1
  306. strict ANSI mode. Inlining is done even when not optimizing (ie. -O0
  307. mode, which is the default), but an unnecessary local copy of foo is
  308. emitted unless -O is used. "extern __inline" is accepted, but the
  309. "extern" appears to be ignored, ie. it becomes a plain global function
  310. but which is inlined within its file. Don't know if all old versions of
  311. DEC C supported __inline, but as a start let's do the right thing for
  312. current versions. */
  313. #ifdef __DECC
  314. #define __GMP_EXTERN_INLINE static __inline
  315. #endif
  316. /* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict
  317. ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes
  318. place under -O. Without -O "foo" seems to be emitted whether it's used
  319. or not, which is wasteful. "extern inline foo()" isn't useful, the
  320. "extern" is apparently ignored, so foo is inlined if possible but also
  321. emitted as a global, which causes multiple definition errors when
  322. building a shared libgmp. */
  323. #ifdef __SCO_VERSION__
  324. #if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \
  325. && ! defined (__GMP_EXTERN_INLINE)
  326. #define __GMP_EXTERN_INLINE static inline
  327. #endif
  328. #endif
  329. /* Microsoft's C compiler accepts __inline */
  330. #ifdef _MSC_VER
  331. #define __GMP_EXTERN_INLINE __inline
  332. #endif
  333. /* Recent enough Sun C compilers want "inline" */
  334. #if defined (__SUNPRO_C) && __SUNPRO_C >= 0x560 \
  335. && ! defined (__GMP_EXTERN_INLINE)
  336. #define __GMP_EXTERN_INLINE inline
  337. #endif
  338. /* Somewhat older Sun C compilers want "static inline" */
  339. #if defined (__SUNPRO_C) && __SUNPRO_C >= 0x540 \
  340. && ! defined (__GMP_EXTERN_INLINE)
  341. #define __GMP_EXTERN_INLINE static inline
  342. #endif
  343. /* C++ always has "inline" and since it's a normal feature the linker should
  344. discard duplicate non-inlined copies, or if it doesn't then that's a
  345. problem for everyone, not just GMP. */
  346. #if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE)
  347. #define __GMP_EXTERN_INLINE inline
  348. #endif
  349. /* Don't do any inlining within a configure run, since if the compiler ends
  350. up emitting copies of the code into the object file it can end up
  351. demanding the various support routines (like mpn_popcount) for linking,
  352. making the "alloca" test and perhaps others fail. And on hppa ia64 a
  353. pre-release gcc 3.2 was seen not respecting the "extern" in "extern
  354. __inline__", triggering this problem too. */
  355. #if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE
  356. #undef __GMP_EXTERN_INLINE
  357. #endif
  358. /* By default, don't give a prototype when there's going to be an inline
  359. version. Note in particular that Cray C++ objects to the combination of
  360. prototype and inline. */
  361. #ifdef __GMP_EXTERN_INLINE
  362. #ifndef __GMP_INLINE_PROTOTYPES
  363. #define __GMP_INLINE_PROTOTYPES 0
  364. #endif
  365. #else
  366. #define __GMP_INLINE_PROTOTYPES 1
  367. #endif
  368. #define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  369. #define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i))
  370. /* __builtin_expect is in gcc 3.0, and not in 2.95. */
  371. #if __GMP_GNUC_PREREQ (3,0)
  372. #define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1)
  373. #define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0)
  374. #else
  375. #define __GMP_LIKELY(cond) (cond)
  376. #define __GMP_UNLIKELY(cond) (cond)
  377. #endif
  378. #ifdef _CRAY
  379. #define __GMP_CRAY_Pragma(str) _Pragma (str)
  380. #else
  381. #define __GMP_CRAY_Pragma(str)
  382. #endif
  383. /* Allow direct user access to numerator and denominator of an mpq_t object. */
  384. #define mpq_numref(Q) (&((Q)->_mp_num))
  385. #define mpq_denref(Q) (&((Q)->_mp_den))
  386. #if defined (__cplusplus)
  387. extern "C" {
  388. using std::FILE;
  389. #endif
  390. #define mp_set_memory_functions __gmp_set_memory_functions
  391. __GMP_DECLSPEC void mp_set_memory_functions (void *(*) (size_t),
  392. void *(*) (void *, size_t, size_t),
  393. void (*) (void *, size_t)) __GMP_NOTHROW;
  394. #define mp_get_memory_functions __gmp_get_memory_functions
  395. __GMP_DECLSPEC void mp_get_memory_functions (void *(**) (size_t),
  396. void *(**) (void *, size_t, size_t),
  397. void (**) (void *, size_t)) __GMP_NOTHROW;
  398. #define mp_bits_per_limb __gmp_bits_per_limb
  399. __GMP_DECLSPEC extern const int mp_bits_per_limb;
  400. #define gmp_errno __gmp_errno
  401. __GMP_DECLSPEC extern int gmp_errno;
  402. #define gmp_version __gmp_version
  403. __GMP_DECLSPEC extern const char * const gmp_version;
  404. /**************** Random number routines. ****************/
  405. /* obsolete */
  406. #define gmp_randinit __gmp_randinit
  407. __GMP_DECLSPEC void gmp_randinit (gmp_randstate_t, gmp_randalg_t, ...);
  408. #define gmp_randinit_default __gmp_randinit_default
  409. __GMP_DECLSPEC void gmp_randinit_default (gmp_randstate_t);
  410. #define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp
  411. __GMP_DECLSPEC void gmp_randinit_lc_2exp (gmp_randstate_t, mpz_srcptr, unsigned long int, mp_bitcnt_t);
  412. #define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size
  413. __GMP_DECLSPEC int gmp_randinit_lc_2exp_size (gmp_randstate_t, mp_bitcnt_t);
  414. #define gmp_randinit_mt __gmp_randinit_mt
  415. __GMP_DECLSPEC void gmp_randinit_mt (gmp_randstate_t);
  416. #define gmp_randinit_set __gmp_randinit_set
  417. __GMP_DECLSPEC void gmp_randinit_set (gmp_randstate_t, const __gmp_randstate_struct *);
  418. #define gmp_randseed __gmp_randseed
  419. __GMP_DECLSPEC void gmp_randseed (gmp_randstate_t, mpz_srcptr);
  420. #define gmp_randseed_ui __gmp_randseed_ui
  421. __GMP_DECLSPEC void gmp_randseed_ui (gmp_randstate_t, unsigned long int);
  422. #define gmp_randclear __gmp_randclear
  423. __GMP_DECLSPEC void gmp_randclear (gmp_randstate_t);
  424. #define gmp_urandomb_ui __gmp_urandomb_ui
  425. __GMP_DECLSPEC unsigned long gmp_urandomb_ui (gmp_randstate_t, unsigned long);
  426. #define gmp_urandomm_ui __gmp_urandomm_ui
  427. __GMP_DECLSPEC unsigned long gmp_urandomm_ui (gmp_randstate_t, unsigned long);
  428. /**************** Formatted output routines. ****************/
  429. #define gmp_asprintf __gmp_asprintf
  430. __GMP_DECLSPEC int gmp_asprintf (char **, const char *, ...);
  431. #define gmp_fprintf __gmp_fprintf
  432. #ifdef _GMP_H_HAVE_FILE
  433. __GMP_DECLSPEC int gmp_fprintf (FILE *, const char *, ...);
  434. #endif
  435. #define gmp_obstack_printf __gmp_obstack_printf
  436. #if defined (_GMP_H_HAVE_OBSTACK)
  437. __GMP_DECLSPEC int gmp_obstack_printf (struct obstack *, const char *, ...);
  438. #endif
  439. #define gmp_obstack_vprintf __gmp_obstack_vprintf
  440. #if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST)
  441. __GMP_DECLSPEC int gmp_obstack_vprintf (struct obstack *, const char *, va_list);
  442. #endif
  443. #define gmp_printf __gmp_printf
  444. __GMP_DECLSPEC int gmp_printf (const char *, ...);
  445. #define gmp_snprintf __gmp_snprintf
  446. __GMP_DECLSPEC int gmp_snprintf (char *, size_t, const char *, ...);
  447. #define gmp_sprintf __gmp_sprintf
  448. __GMP_DECLSPEC int gmp_sprintf (char *, const char *, ...);
  449. #define gmp_vasprintf __gmp_vasprintf
  450. #if defined (_GMP_H_HAVE_VA_LIST)
  451. __GMP_DECLSPEC int gmp_vasprintf (char **, const char *, va_list);
  452. #endif
  453. #define gmp_vfprintf __gmp_vfprintf
  454. #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
  455. __GMP_DECLSPEC int gmp_vfprintf (FILE *, const char *, va_list);
  456. #endif
  457. #define gmp_vprintf __gmp_vprintf
  458. #if defined (_GMP_H_HAVE_VA_LIST)
  459. __GMP_DECLSPEC int gmp_vprintf (const char *, va_list);
  460. #endif
  461. #define gmp_vsnprintf __gmp_vsnprintf
  462. #if defined (_GMP_H_HAVE_VA_LIST)
  463. __GMP_DECLSPEC int gmp_vsnprintf (char *, size_t, const char *, va_list);
  464. #endif
  465. #define gmp_vsprintf __gmp_vsprintf
  466. #if defined (_GMP_H_HAVE_VA_LIST)
  467. __GMP_DECLSPEC int gmp_vsprintf (char *, const char *, va_list);
  468. #endif
  469. /**************** Formatted input routines. ****************/
  470. #define gmp_fscanf __gmp_fscanf
  471. #ifdef _GMP_H_HAVE_FILE
  472. __GMP_DECLSPEC int gmp_fscanf (FILE *, const char *, ...);
  473. #endif
  474. #define gmp_scanf __gmp_scanf
  475. __GMP_DECLSPEC int gmp_scanf (const char *, ...);
  476. #define gmp_sscanf __gmp_sscanf
  477. __GMP_DECLSPEC int gmp_sscanf (const char *, const char *, ...);
  478. #define gmp_vfscanf __gmp_vfscanf
  479. #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
  480. __GMP_DECLSPEC int gmp_vfscanf (FILE *, const char *, va_list);
  481. #endif
  482. #define gmp_vscanf __gmp_vscanf
  483. #if defined (_GMP_H_HAVE_VA_LIST)
  484. __GMP_DECLSPEC int gmp_vscanf (const char *, va_list);
  485. #endif
  486. #define gmp_vsscanf __gmp_vsscanf
  487. #if defined (_GMP_H_HAVE_VA_LIST)
  488. __GMP_DECLSPEC int gmp_vsscanf (const char *, const char *, va_list);
  489. #endif
  490. /**************** Integer (i.e. Z) routines. ****************/
  491. #define _mpz_realloc __gmpz_realloc
  492. #define mpz_realloc __gmpz_realloc
  493. __GMP_DECLSPEC void *_mpz_realloc (mpz_ptr, mp_size_t);
  494. #define mpz_abs __gmpz_abs
  495. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs)
  496. __GMP_DECLSPEC void mpz_abs (mpz_ptr, mpz_srcptr);
  497. #endif
  498. #define mpz_add __gmpz_add
  499. __GMP_DECLSPEC void mpz_add (mpz_ptr, mpz_srcptr, mpz_srcptr);
  500. #define mpz_add_ui __gmpz_add_ui
  501. __GMP_DECLSPEC void mpz_add_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  502. #define mpz_addmul __gmpz_addmul
  503. __GMP_DECLSPEC void mpz_addmul (mpz_ptr, mpz_srcptr, mpz_srcptr);
  504. #define mpz_addmul_ui __gmpz_addmul_ui
  505. __GMP_DECLSPEC void mpz_addmul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  506. #define mpz_and __gmpz_and
  507. __GMP_DECLSPEC void mpz_and (mpz_ptr, mpz_srcptr, mpz_srcptr);
  508. #define mpz_array_init __gmpz_array_init
  509. __GMP_DECLSPEC void mpz_array_init (mpz_ptr, mp_size_t, mp_size_t);
  510. #define mpz_bin_ui __gmpz_bin_ui
  511. __GMP_DECLSPEC void mpz_bin_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  512. #define mpz_bin_uiui __gmpz_bin_uiui
  513. __GMP_DECLSPEC void mpz_bin_uiui (mpz_ptr, unsigned long int, unsigned long int);
  514. #define mpz_cdiv_q __gmpz_cdiv_q
  515. __GMP_DECLSPEC void mpz_cdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
  516. #define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp
  517. __GMP_DECLSPEC void mpz_cdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  518. #define mpz_cdiv_q_ui __gmpz_cdiv_q_ui
  519. __GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  520. #define mpz_cdiv_qr __gmpz_cdiv_qr
  521. __GMP_DECLSPEC void mpz_cdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
  522. #define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui
  523. __GMP_DECLSPEC unsigned long int mpz_cdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
  524. #define mpz_cdiv_r __gmpz_cdiv_r
  525. __GMP_DECLSPEC void mpz_cdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
  526. #define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp
  527. __GMP_DECLSPEC void mpz_cdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  528. #define mpz_cdiv_r_ui __gmpz_cdiv_r_ui
  529. __GMP_DECLSPEC unsigned long int mpz_cdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  530. #define mpz_cdiv_ui __gmpz_cdiv_ui
  531. __GMP_DECLSPEC unsigned long int mpz_cdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE;
  532. #define mpz_clear __gmpz_clear
  533. __GMP_DECLSPEC void mpz_clear (mpz_ptr);
  534. #define mpz_clears __gmpz_clears
  535. __GMP_DECLSPEC void mpz_clears (mpz_ptr, ...);
  536. #define mpz_clrbit __gmpz_clrbit
  537. __GMP_DECLSPEC void mpz_clrbit (mpz_ptr, mp_bitcnt_t);
  538. #define mpz_cmp __gmpz_cmp
  539. __GMP_DECLSPEC int mpz_cmp (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  540. #define mpz_cmp_d __gmpz_cmp_d
  541. __GMP_DECLSPEC int mpz_cmp_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE;
  542. #define _mpz_cmp_si __gmpz_cmp_si
  543. __GMP_DECLSPEC int _mpz_cmp_si (mpz_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  544. #define _mpz_cmp_ui __gmpz_cmp_ui
  545. __GMP_DECLSPEC int _mpz_cmp_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  546. #define mpz_cmpabs __gmpz_cmpabs
  547. __GMP_DECLSPEC int mpz_cmpabs (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  548. #define mpz_cmpabs_d __gmpz_cmpabs_d
  549. __GMP_DECLSPEC int mpz_cmpabs_d (mpz_srcptr, double) __GMP_ATTRIBUTE_PURE;
  550. #define mpz_cmpabs_ui __gmpz_cmpabs_ui
  551. __GMP_DECLSPEC int mpz_cmpabs_ui (mpz_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  552. #define mpz_com __gmpz_com
  553. __GMP_DECLSPEC void mpz_com (mpz_ptr, mpz_srcptr);
  554. #define mpz_combit __gmpz_combit
  555. __GMP_DECLSPEC void mpz_combit (mpz_ptr, mp_bitcnt_t);
  556. #define mpz_congruent_p __gmpz_congruent_p
  557. __GMP_DECLSPEC int mpz_congruent_p (mpz_srcptr, mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  558. #define mpz_congruent_2exp_p __gmpz_congruent_2exp_p
  559. __GMP_DECLSPEC int mpz_congruent_2exp_p (mpz_srcptr, mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  560. #define mpz_congruent_ui_p __gmpz_congruent_ui_p
  561. __GMP_DECLSPEC int mpz_congruent_ui_p (mpz_srcptr, unsigned long, unsigned long) __GMP_ATTRIBUTE_PURE;
  562. #define mpz_divexact __gmpz_divexact
  563. __GMP_DECLSPEC void mpz_divexact (mpz_ptr, mpz_srcptr, mpz_srcptr);
  564. #define mpz_divexact_ui __gmpz_divexact_ui
  565. __GMP_DECLSPEC void mpz_divexact_ui (mpz_ptr, mpz_srcptr, unsigned long);
  566. #define mpz_divisible_p __gmpz_divisible_p
  567. __GMP_DECLSPEC int mpz_divisible_p (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  568. #define mpz_divisible_ui_p __gmpz_divisible_ui_p
  569. __GMP_DECLSPEC int mpz_divisible_ui_p (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE;
  570. #define mpz_divisible_2exp_p __gmpz_divisible_2exp_p
  571. __GMP_DECLSPEC int mpz_divisible_2exp_p (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  572. #define mpz_dump __gmpz_dump
  573. __GMP_DECLSPEC void mpz_dump (mpz_srcptr);
  574. #define mpz_export __gmpz_export
  575. __GMP_DECLSPEC void *mpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr);
  576. #define mpz_fac_ui __gmpz_fac_ui
  577. __GMP_DECLSPEC void mpz_fac_ui (mpz_ptr, unsigned long int);
  578. #define mpz_2fac_ui __gmpz_2fac_ui
  579. __GMP_DECLSPEC void mpz_2fac_ui (mpz_ptr, unsigned long int);
  580. #define mpz_mfac_uiui __gmpz_mfac_uiui
  581. __GMP_DECLSPEC void mpz_mfac_uiui (mpz_ptr, unsigned long int, unsigned long int);
  582. #define mpz_primorial_ui __gmpz_primorial_ui
  583. __GMP_DECLSPEC void mpz_primorial_ui (mpz_ptr, unsigned long int);
  584. #define mpz_fdiv_q __gmpz_fdiv_q
  585. __GMP_DECLSPEC void mpz_fdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
  586. #define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp
  587. __GMP_DECLSPEC void mpz_fdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  588. #define mpz_fdiv_q_ui __gmpz_fdiv_q_ui
  589. __GMP_DECLSPEC unsigned long int mpz_fdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  590. #define mpz_fdiv_qr __gmpz_fdiv_qr
  591. __GMP_DECLSPEC void mpz_fdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
  592. #define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui
  593. __GMP_DECLSPEC unsigned long int mpz_fdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
  594. #define mpz_fdiv_r __gmpz_fdiv_r
  595. __GMP_DECLSPEC void mpz_fdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
  596. #define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp
  597. __GMP_DECLSPEC void mpz_fdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  598. #define mpz_fdiv_r_ui __gmpz_fdiv_r_ui
  599. __GMP_DECLSPEC unsigned long int mpz_fdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  600. #define mpz_fdiv_ui __gmpz_fdiv_ui
  601. __GMP_DECLSPEC unsigned long int mpz_fdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE;
  602. #define mpz_fib_ui __gmpz_fib_ui
  603. __GMP_DECLSPEC void mpz_fib_ui (mpz_ptr, unsigned long int);
  604. #define mpz_fib2_ui __gmpz_fib2_ui
  605. __GMP_DECLSPEC void mpz_fib2_ui (mpz_ptr, mpz_ptr, unsigned long int);
  606. #define mpz_fits_sint_p __gmpz_fits_sint_p
  607. __GMP_DECLSPEC int mpz_fits_sint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  608. #define mpz_fits_slong_p __gmpz_fits_slong_p
  609. __GMP_DECLSPEC int mpz_fits_slong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  610. #define mpz_fits_sshort_p __gmpz_fits_sshort_p
  611. __GMP_DECLSPEC int mpz_fits_sshort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  612. #define mpz_fits_uint_p __gmpz_fits_uint_p
  613. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p)
  614. __GMP_DECLSPEC int mpz_fits_uint_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  615. #endif
  616. #define mpz_fits_ulong_p __gmpz_fits_ulong_p
  617. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p)
  618. __GMP_DECLSPEC int mpz_fits_ulong_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  619. #endif
  620. #define mpz_fits_ushort_p __gmpz_fits_ushort_p
  621. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p)
  622. __GMP_DECLSPEC int mpz_fits_ushort_p (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  623. #endif
  624. #define mpz_gcd __gmpz_gcd
  625. __GMP_DECLSPEC void mpz_gcd (mpz_ptr, mpz_srcptr, mpz_srcptr);
  626. #define mpz_gcd_ui __gmpz_gcd_ui
  627. __GMP_DECLSPEC unsigned long int mpz_gcd_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  628. #define mpz_gcdext __gmpz_gcdext
  629. __GMP_DECLSPEC void mpz_gcdext (mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
  630. #define mpz_get_d __gmpz_get_d
  631. __GMP_DECLSPEC double mpz_get_d (mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  632. #define mpz_get_d_2exp __gmpz_get_d_2exp
  633. __GMP_DECLSPEC double mpz_get_d_2exp (signed long int *, mpz_srcptr);
  634. #define mpz_get_si __gmpz_get_si
  635. __GMP_DECLSPEC /* signed */ long int mpz_get_si (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  636. #define mpz_get_str __gmpz_get_str
  637. __GMP_DECLSPEC char *mpz_get_str (char *, int, mpz_srcptr);
  638. #define mpz_get_ui __gmpz_get_ui
  639. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui)
  640. __GMP_DECLSPEC unsigned long int mpz_get_ui (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  641. #endif
  642. #define mpz_getlimbn __gmpz_getlimbn
  643. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn)
  644. __GMP_DECLSPEC mp_limb_t mpz_getlimbn (mpz_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  645. #endif
  646. #define mpz_hamdist __gmpz_hamdist
  647. __GMP_DECLSPEC mp_bitcnt_t mpz_hamdist (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  648. #define mpz_import __gmpz_import
  649. __GMP_DECLSPEC void mpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *);
  650. #define mpz_init __gmpz_init
  651. __GMP_DECLSPEC void mpz_init (mpz_ptr) __GMP_NOTHROW;
  652. #define mpz_init2 __gmpz_init2
  653. __GMP_DECLSPEC void mpz_init2 (mpz_ptr, mp_bitcnt_t);
  654. #define mpz_inits __gmpz_inits
  655. __GMP_DECLSPEC void mpz_inits (mpz_ptr, ...) __GMP_NOTHROW;
  656. #define mpz_init_set __gmpz_init_set
  657. __GMP_DECLSPEC void mpz_init_set (mpz_ptr, mpz_srcptr);
  658. #define mpz_init_set_d __gmpz_init_set_d
  659. __GMP_DECLSPEC void mpz_init_set_d (mpz_ptr, double);
  660. #define mpz_init_set_si __gmpz_init_set_si
  661. __GMP_DECLSPEC void mpz_init_set_si (mpz_ptr, signed long int);
  662. #define mpz_init_set_str __gmpz_init_set_str
  663. __GMP_DECLSPEC int mpz_init_set_str (mpz_ptr, const char *, int);
  664. #define mpz_init_set_ui __gmpz_init_set_ui
  665. __GMP_DECLSPEC void mpz_init_set_ui (mpz_ptr, unsigned long int);
  666. #define mpz_inp_raw __gmpz_inp_raw
  667. #ifdef _GMP_H_HAVE_FILE
  668. __GMP_DECLSPEC size_t mpz_inp_raw (mpz_ptr, FILE *);
  669. #endif
  670. #define mpz_inp_str __gmpz_inp_str
  671. #ifdef _GMP_H_HAVE_FILE
  672. __GMP_DECLSPEC size_t mpz_inp_str (mpz_ptr, FILE *, int);
  673. #endif
  674. #define mpz_invert __gmpz_invert
  675. __GMP_DECLSPEC int mpz_invert (mpz_ptr, mpz_srcptr, mpz_srcptr);
  676. #define mpz_ior __gmpz_ior
  677. __GMP_DECLSPEC void mpz_ior (mpz_ptr, mpz_srcptr, mpz_srcptr);
  678. #define mpz_jacobi __gmpz_jacobi
  679. __GMP_DECLSPEC int mpz_jacobi (mpz_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  680. #define mpz_kronecker mpz_jacobi /* alias */
  681. #define mpz_kronecker_si __gmpz_kronecker_si
  682. __GMP_DECLSPEC int mpz_kronecker_si (mpz_srcptr, long) __GMP_ATTRIBUTE_PURE;
  683. #define mpz_kronecker_ui __gmpz_kronecker_ui
  684. __GMP_DECLSPEC int mpz_kronecker_ui (mpz_srcptr, unsigned long) __GMP_ATTRIBUTE_PURE;
  685. #define mpz_si_kronecker __gmpz_si_kronecker
  686. __GMP_DECLSPEC int mpz_si_kronecker (long, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  687. #define mpz_ui_kronecker __gmpz_ui_kronecker
  688. __GMP_DECLSPEC int mpz_ui_kronecker (unsigned long, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  689. #define mpz_lcm __gmpz_lcm
  690. __GMP_DECLSPEC void mpz_lcm (mpz_ptr, mpz_srcptr, mpz_srcptr);
  691. #define mpz_lcm_ui __gmpz_lcm_ui
  692. __GMP_DECLSPEC void mpz_lcm_ui (mpz_ptr, mpz_srcptr, unsigned long);
  693. #define mpz_legendre mpz_jacobi /* alias */
  694. #define mpz_lucnum_ui __gmpz_lucnum_ui
  695. __GMP_DECLSPEC void mpz_lucnum_ui (mpz_ptr, unsigned long int);
  696. #define mpz_lucnum2_ui __gmpz_lucnum2_ui
  697. __GMP_DECLSPEC void mpz_lucnum2_ui (mpz_ptr, mpz_ptr, unsigned long int);
  698. #define mpz_millerrabin __gmpz_millerrabin
  699. __GMP_DECLSPEC int mpz_millerrabin (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE;
  700. #define mpz_mod __gmpz_mod
  701. __GMP_DECLSPEC void mpz_mod (mpz_ptr, mpz_srcptr, mpz_srcptr);
  702. #define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */
  703. #define mpz_mul __gmpz_mul
  704. __GMP_DECLSPEC void mpz_mul (mpz_ptr, mpz_srcptr, mpz_srcptr);
  705. #define mpz_mul_2exp __gmpz_mul_2exp
  706. __GMP_DECLSPEC void mpz_mul_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  707. #define mpz_mul_si __gmpz_mul_si
  708. __GMP_DECLSPEC void mpz_mul_si (mpz_ptr, mpz_srcptr, long int);
  709. #define mpz_mul_ui __gmpz_mul_ui
  710. __GMP_DECLSPEC void mpz_mul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  711. #define mpz_neg __gmpz_neg
  712. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg)
  713. __GMP_DECLSPEC void mpz_neg (mpz_ptr, mpz_srcptr);
  714. #endif
  715. #define mpz_nextprime __gmpz_nextprime
  716. __GMP_DECLSPEC void mpz_nextprime (mpz_ptr, mpz_srcptr);
  717. #define mpz_out_raw __gmpz_out_raw
  718. #ifdef _GMP_H_HAVE_FILE
  719. __GMP_DECLSPEC size_t mpz_out_raw (FILE *, mpz_srcptr);
  720. #endif
  721. #define mpz_out_str __gmpz_out_str
  722. #ifdef _GMP_H_HAVE_FILE
  723. __GMP_DECLSPEC size_t mpz_out_str (FILE *, int, mpz_srcptr);
  724. #endif
  725. #define mpz_perfect_power_p __gmpz_perfect_power_p
  726. __GMP_DECLSPEC int mpz_perfect_power_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  727. #define mpz_perfect_square_p __gmpz_perfect_square_p
  728. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p)
  729. __GMP_DECLSPEC int mpz_perfect_square_p (mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  730. #endif
  731. #define mpz_popcount __gmpz_popcount
  732. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount)
  733. __GMP_DECLSPEC mp_bitcnt_t mpz_popcount (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  734. #endif
  735. #define mpz_pow_ui __gmpz_pow_ui
  736. __GMP_DECLSPEC void mpz_pow_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  737. #define mpz_powm __gmpz_powm
  738. __GMP_DECLSPEC void mpz_powm (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
  739. #define mpz_powm_sec __gmpz_powm_sec
  740. __GMP_DECLSPEC void mpz_powm_sec (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
  741. #define mpz_powm_ui __gmpz_powm_ui
  742. __GMP_DECLSPEC void mpz_powm_ui (mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr);
  743. #define mpz_probab_prime_p __gmpz_probab_prime_p
  744. __GMP_DECLSPEC int mpz_probab_prime_p (mpz_srcptr, int) __GMP_ATTRIBUTE_PURE;
  745. #define mpz_random __gmpz_random
  746. __GMP_DECLSPEC void mpz_random (mpz_ptr, mp_size_t);
  747. #define mpz_random2 __gmpz_random2
  748. __GMP_DECLSPEC void mpz_random2 (mpz_ptr, mp_size_t);
  749. #define mpz_realloc2 __gmpz_realloc2
  750. __GMP_DECLSPEC void mpz_realloc2 (mpz_ptr, mp_bitcnt_t);
  751. #define mpz_remove __gmpz_remove
  752. __GMP_DECLSPEC mp_bitcnt_t mpz_remove (mpz_ptr, mpz_srcptr, mpz_srcptr);
  753. #define mpz_root __gmpz_root
  754. __GMP_DECLSPEC int mpz_root (mpz_ptr, mpz_srcptr, unsigned long int);
  755. #define mpz_rootrem __gmpz_rootrem
  756. __GMP_DECLSPEC void mpz_rootrem (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
  757. #define mpz_rrandomb __gmpz_rrandomb
  758. __GMP_DECLSPEC void mpz_rrandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t);
  759. #define mpz_scan0 __gmpz_scan0
  760. __GMP_DECLSPEC mp_bitcnt_t mpz_scan0 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  761. #define mpz_scan1 __gmpz_scan1
  762. __GMP_DECLSPEC mp_bitcnt_t mpz_scan1 (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  763. #define mpz_set __gmpz_set
  764. __GMP_DECLSPEC void mpz_set (mpz_ptr, mpz_srcptr);
  765. #define mpz_set_d __gmpz_set_d
  766. __GMP_DECLSPEC void mpz_set_d (mpz_ptr, double);
  767. #define mpz_set_f __gmpz_set_f
  768. __GMP_DECLSPEC void mpz_set_f (mpz_ptr, mpf_srcptr);
  769. #define mpz_set_q __gmpz_set_q
  770. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q)
  771. __GMP_DECLSPEC void mpz_set_q (mpz_ptr, mpq_srcptr);
  772. #endif
  773. #define mpz_set_si __gmpz_set_si
  774. __GMP_DECLSPEC void mpz_set_si (mpz_ptr, signed long int);
  775. #define mpz_set_str __gmpz_set_str
  776. __GMP_DECLSPEC int mpz_set_str (mpz_ptr, const char *, int);
  777. #define mpz_set_ui __gmpz_set_ui
  778. __GMP_DECLSPEC void mpz_set_ui (mpz_ptr, unsigned long int);
  779. #define mpz_setbit __gmpz_setbit
  780. __GMP_DECLSPEC void mpz_setbit (mpz_ptr, mp_bitcnt_t);
  781. #define mpz_size __gmpz_size
  782. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size)
  783. __GMP_DECLSPEC size_t mpz_size (mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  784. #endif
  785. #define mpz_sizeinbase __gmpz_sizeinbase
  786. __GMP_DECLSPEC size_t mpz_sizeinbase (mpz_srcptr, int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  787. #define mpz_sqrt __gmpz_sqrt
  788. __GMP_DECLSPEC void mpz_sqrt (mpz_ptr, mpz_srcptr);
  789. #define mpz_sqrtrem __gmpz_sqrtrem
  790. __GMP_DECLSPEC void mpz_sqrtrem (mpz_ptr, mpz_ptr, mpz_srcptr);
  791. #define mpz_sub __gmpz_sub
  792. __GMP_DECLSPEC void mpz_sub (mpz_ptr, mpz_srcptr, mpz_srcptr);
  793. #define mpz_sub_ui __gmpz_sub_ui
  794. __GMP_DECLSPEC void mpz_sub_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  795. #define mpz_ui_sub __gmpz_ui_sub
  796. __GMP_DECLSPEC void mpz_ui_sub (mpz_ptr, unsigned long int, mpz_srcptr);
  797. #define mpz_submul __gmpz_submul
  798. __GMP_DECLSPEC void mpz_submul (mpz_ptr, mpz_srcptr, mpz_srcptr);
  799. #define mpz_submul_ui __gmpz_submul_ui
  800. __GMP_DECLSPEC void mpz_submul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  801. #define mpz_swap __gmpz_swap
  802. __GMP_DECLSPEC void mpz_swap (mpz_ptr, mpz_ptr) __GMP_NOTHROW;
  803. #define mpz_tdiv_ui __gmpz_tdiv_ui
  804. __GMP_DECLSPEC unsigned long int mpz_tdiv_ui (mpz_srcptr, unsigned long int) __GMP_ATTRIBUTE_PURE;
  805. #define mpz_tdiv_q __gmpz_tdiv_q
  806. __GMP_DECLSPEC void mpz_tdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
  807. #define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp
  808. __GMP_DECLSPEC void mpz_tdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  809. #define mpz_tdiv_q_ui __gmpz_tdiv_q_ui
  810. __GMP_DECLSPEC unsigned long int mpz_tdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  811. #define mpz_tdiv_qr __gmpz_tdiv_qr
  812. __GMP_DECLSPEC void mpz_tdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
  813. #define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui
  814. __GMP_DECLSPEC unsigned long int mpz_tdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
  815. #define mpz_tdiv_r __gmpz_tdiv_r
  816. __GMP_DECLSPEC void mpz_tdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
  817. #define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp
  818. __GMP_DECLSPEC void mpz_tdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
  819. #define mpz_tdiv_r_ui __gmpz_tdiv_r_ui
  820. __GMP_DECLSPEC unsigned long int mpz_tdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
  821. #define mpz_tstbit __gmpz_tstbit
  822. __GMP_DECLSPEC int mpz_tstbit (mpz_srcptr, mp_bitcnt_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  823. #define mpz_ui_pow_ui __gmpz_ui_pow_ui
  824. __GMP_DECLSPEC void mpz_ui_pow_ui (mpz_ptr, unsigned long int, unsigned long int);
  825. #define mpz_urandomb __gmpz_urandomb
  826. __GMP_DECLSPEC void mpz_urandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t);
  827. #define mpz_urandomm __gmpz_urandomm
  828. __GMP_DECLSPEC void mpz_urandomm (mpz_ptr, gmp_randstate_t, mpz_srcptr);
  829. #define mpz_xor __gmpz_xor
  830. #define mpz_eor __gmpz_xor
  831. __GMP_DECLSPEC void mpz_xor (mpz_ptr, mpz_srcptr, mpz_srcptr);
  832. #define mpz_limbs_read __gmpz_limbs_read
  833. __GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr);
  834. #define mpz_limbs_write __gmpz_limbs_write
  835. __GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t);
  836. #define mpz_limbs_modify __gmpz_limbs_modify
  837. __GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t);
  838. #define mpz_limbs_finish __gmpz_limbs_finish
  839. __GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t);
  840. #define mpz_roinit_n __gmpz_roinit_n
  841. __GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t);
  842. #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
  843. /**************** Rational (i.e. Q) routines. ****************/
  844. #define mpq_abs __gmpq_abs
  845. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs)
  846. __GMP_DECLSPEC void mpq_abs (mpq_ptr, mpq_srcptr);
  847. #endif
  848. #define mpq_add __gmpq_add
  849. __GMP_DECLSPEC void mpq_add (mpq_ptr, mpq_srcptr, mpq_srcptr);
  850. #define mpq_canonicalize __gmpq_canonicalize
  851. __GMP_DECLSPEC void mpq_canonicalize (mpq_ptr);
  852. #define mpq_clear __gmpq_clear
  853. __GMP_DECLSPEC void mpq_clear (mpq_ptr);
  854. #define mpq_clears __gmpq_clears
  855. __GMP_DECLSPEC void mpq_clears (mpq_ptr, ...);
  856. #define mpq_cmp __gmpq_cmp
  857. __GMP_DECLSPEC int mpq_cmp (mpq_srcptr, mpq_srcptr) __GMP_ATTRIBUTE_PURE;
  858. #define _mpq_cmp_si __gmpq_cmp_si
  859. __GMP_DECLSPEC int _mpq_cmp_si (mpq_srcptr, long, unsigned long) __GMP_ATTRIBUTE_PURE;
  860. #define _mpq_cmp_ui __gmpq_cmp_ui
  861. __GMP_DECLSPEC int _mpq_cmp_ui (mpq_srcptr, unsigned long int, unsigned long int) __GMP_ATTRIBUTE_PURE;
  862. #define mpq_cmp_z __gmpq_cmp_z
  863. __GMP_DECLSPEC int mpq_cmp_z (mpq_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE;
  864. #define mpq_div __gmpq_div
  865. __GMP_DECLSPEC void mpq_div (mpq_ptr, mpq_srcptr, mpq_srcptr);
  866. #define mpq_div_2exp __gmpq_div_2exp
  867. __GMP_DECLSPEC void mpq_div_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t);
  868. #define mpq_equal __gmpq_equal
  869. __GMP_DECLSPEC int mpq_equal (mpq_srcptr, mpq_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  870. #define mpq_get_num __gmpq_get_num
  871. __GMP_DECLSPEC void mpq_get_num (mpz_ptr, mpq_srcptr);
  872. #define mpq_get_den __gmpq_get_den
  873. __GMP_DECLSPEC void mpq_get_den (mpz_ptr, mpq_srcptr);
  874. #define mpq_get_d __gmpq_get_d
  875. __GMP_DECLSPEC double mpq_get_d (mpq_srcptr) __GMP_ATTRIBUTE_PURE;
  876. #define mpq_get_str __gmpq_get_str
  877. __GMP_DECLSPEC char *mpq_get_str (char *, int, mpq_srcptr);
  878. #define mpq_init __gmpq_init
  879. __GMP_DECLSPEC void mpq_init (mpq_ptr);
  880. #define mpq_inits __gmpq_inits
  881. __GMP_DECLSPEC void mpq_inits (mpq_ptr, ...);
  882. #define mpq_inp_str __gmpq_inp_str
  883. #ifdef _GMP_H_HAVE_FILE
  884. __GMP_DECLSPEC size_t mpq_inp_str (mpq_ptr, FILE *, int);
  885. #endif
  886. #define mpq_inv __gmpq_inv
  887. __GMP_DECLSPEC void mpq_inv (mpq_ptr, mpq_srcptr);
  888. #define mpq_mul __gmpq_mul
  889. __GMP_DECLSPEC void mpq_mul (mpq_ptr, mpq_srcptr, mpq_srcptr);
  890. #define mpq_mul_2exp __gmpq_mul_2exp
  891. __GMP_DECLSPEC void mpq_mul_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t);
  892. #define mpq_neg __gmpq_neg
  893. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg)
  894. __GMP_DECLSPEC void mpq_neg (mpq_ptr, mpq_srcptr);
  895. #endif
  896. #define mpq_out_str __gmpq_out_str
  897. #ifdef _GMP_H_HAVE_FILE
  898. __GMP_DECLSPEC size_t mpq_out_str (FILE *, int, mpq_srcptr);
  899. #endif
  900. #define mpq_set __gmpq_set
  901. __GMP_DECLSPEC void mpq_set (mpq_ptr, mpq_srcptr);
  902. #define mpq_set_d __gmpq_set_d
  903. __GMP_DECLSPEC void mpq_set_d (mpq_ptr, double);
  904. #define mpq_set_den __gmpq_set_den
  905. __GMP_DECLSPEC void mpq_set_den (mpq_ptr, mpz_srcptr);
  906. #define mpq_set_f __gmpq_set_f
  907. __GMP_DECLSPEC void mpq_set_f (mpq_ptr, mpf_srcptr);
  908. #define mpq_set_num __gmpq_set_num
  909. __GMP_DECLSPEC void mpq_set_num (mpq_ptr, mpz_srcptr);
  910. #define mpq_set_si __gmpq_set_si
  911. __GMP_DECLSPEC void mpq_set_si (mpq_ptr, signed long int, unsigned long int);
  912. #define mpq_set_str __gmpq_set_str
  913. __GMP_DECLSPEC int mpq_set_str (mpq_ptr, const char *, int);
  914. #define mpq_set_ui __gmpq_set_ui
  915. __GMP_DECLSPEC void mpq_set_ui (mpq_ptr, unsigned long int, unsigned long int);
  916. #define mpq_set_z __gmpq_set_z
  917. __GMP_DECLSPEC void mpq_set_z (mpq_ptr, mpz_srcptr);
  918. #define mpq_sub __gmpq_sub
  919. __GMP_DECLSPEC void mpq_sub (mpq_ptr, mpq_srcptr, mpq_srcptr);
  920. #define mpq_swap __gmpq_swap
  921. __GMP_DECLSPEC void mpq_swap (mpq_ptr, mpq_ptr) __GMP_NOTHROW;
  922. /**************** Float (i.e. F) routines. ****************/
  923. #define mpf_abs __gmpf_abs
  924. __GMP_DECLSPEC void mpf_abs (mpf_ptr, mpf_srcptr);
  925. #define mpf_add __gmpf_add
  926. __GMP_DECLSPEC void mpf_add (mpf_ptr, mpf_srcptr, mpf_srcptr);
  927. #define mpf_add_ui __gmpf_add_ui
  928. __GMP_DECLSPEC void mpf_add_ui (mpf_ptr, mpf_srcptr, unsigned long int);
  929. #define mpf_ceil __gmpf_ceil
  930. __GMP_DECLSPEC void mpf_ceil (mpf_ptr, mpf_srcptr);
  931. #define mpf_clear __gmpf_clear
  932. __GMP_DECLSPEC void mpf_clear (mpf_ptr);
  933. #define mpf_clears __gmpf_clears
  934. __GMP_DECLSPEC void mpf_clears (mpf_ptr, ...);
  935. #define mpf_cmp __gmpf_cmp
  936. __GMP_DECLSPEC int mpf_cmp (mpf_srcptr, mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  937. #define mpf_cmp_z __gmpf_cmp_z
  938. __GMP_DECLSPEC int mpf_cmp_z (mpf_srcptr, mpz_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  939. #define mpf_cmp_d __gmpf_cmp_d
  940. __GMP_DECLSPEC int mpf_cmp_d (mpf_srcptr, double) __GMP_ATTRIBUTE_PURE;
  941. #define mpf_cmp_si __gmpf_cmp_si
  942. __GMP_DECLSPEC int mpf_cmp_si (mpf_srcptr, signed long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  943. #define mpf_cmp_ui __gmpf_cmp_ui
  944. __GMP_DECLSPEC int mpf_cmp_ui (mpf_srcptr, unsigned long int) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  945. #define mpf_div __gmpf_div
  946. __GMP_DECLSPEC void mpf_div (mpf_ptr, mpf_srcptr, mpf_srcptr);
  947. #define mpf_div_2exp __gmpf_div_2exp
  948. __GMP_DECLSPEC void mpf_div_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t);
  949. #define mpf_div_ui __gmpf_div_ui
  950. __GMP_DECLSPEC void mpf_div_ui (mpf_ptr, mpf_srcptr, unsigned long int);
  951. #define mpf_dump __gmpf_dump
  952. __GMP_DECLSPEC void mpf_dump (mpf_srcptr);
  953. #define mpf_eq __gmpf_eq
  954. __GMP_DECLSPEC int mpf_eq (mpf_srcptr, mpf_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE;
  955. #define mpf_fits_sint_p __gmpf_fits_sint_p
  956. __GMP_DECLSPEC int mpf_fits_sint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  957. #define mpf_fits_slong_p __gmpf_fits_slong_p
  958. __GMP_DECLSPEC int mpf_fits_slong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  959. #define mpf_fits_sshort_p __gmpf_fits_sshort_p
  960. __GMP_DECLSPEC int mpf_fits_sshort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  961. #define mpf_fits_uint_p __gmpf_fits_uint_p
  962. __GMP_DECLSPEC int mpf_fits_uint_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  963. #define mpf_fits_ulong_p __gmpf_fits_ulong_p
  964. __GMP_DECLSPEC int mpf_fits_ulong_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  965. #define mpf_fits_ushort_p __gmpf_fits_ushort_p
  966. __GMP_DECLSPEC int mpf_fits_ushort_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  967. #define mpf_floor __gmpf_floor
  968. __GMP_DECLSPEC void mpf_floor (mpf_ptr, mpf_srcptr);
  969. #define mpf_get_d __gmpf_get_d
  970. __GMP_DECLSPEC double mpf_get_d (mpf_srcptr) __GMP_ATTRIBUTE_PURE;
  971. #define mpf_get_d_2exp __gmpf_get_d_2exp
  972. __GMP_DECLSPEC double mpf_get_d_2exp (signed long int *, mpf_srcptr);
  973. #define mpf_get_default_prec __gmpf_get_default_prec
  974. __GMP_DECLSPEC mp_bitcnt_t mpf_get_default_prec (void) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  975. #define mpf_get_prec __gmpf_get_prec
  976. __GMP_DECLSPEC mp_bitcnt_t mpf_get_prec (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  977. #define mpf_get_si __gmpf_get_si
  978. __GMP_DECLSPEC long mpf_get_si (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  979. #define mpf_get_str __gmpf_get_str
  980. __GMP_DECLSPEC char *mpf_get_str (char *, mp_exp_t *, int, size_t, mpf_srcptr);
  981. #define mpf_get_ui __gmpf_get_ui
  982. __GMP_DECLSPEC unsigned long mpf_get_ui (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  983. #define mpf_init __gmpf_init
  984. __GMP_DECLSPEC void mpf_init (mpf_ptr);
  985. #define mpf_init2 __gmpf_init2
  986. __GMP_DECLSPEC void mpf_init2 (mpf_ptr, mp_bitcnt_t);
  987. #define mpf_inits __gmpf_inits
  988. __GMP_DECLSPEC void mpf_inits (mpf_ptr, ...);
  989. #define mpf_init_set __gmpf_init_set
  990. __GMP_DECLSPEC void mpf_init_set (mpf_ptr, mpf_srcptr);
  991. #define mpf_init_set_d __gmpf_init_set_d
  992. __GMP_DECLSPEC void mpf_init_set_d (mpf_ptr, double);
  993. #define mpf_init_set_si __gmpf_init_set_si
  994. __GMP_DECLSPEC void mpf_init_set_si (mpf_ptr, signed long int);
  995. #define mpf_init_set_str __gmpf_init_set_str
  996. __GMP_DECLSPEC int mpf_init_set_str (mpf_ptr, const char *, int);
  997. #define mpf_init_set_ui __gmpf_init_set_ui
  998. __GMP_DECLSPEC void mpf_init_set_ui (mpf_ptr, unsigned long int);
  999. #define mpf_inp_str __gmpf_inp_str
  1000. #ifdef _GMP_H_HAVE_FILE
  1001. __GMP_DECLSPEC size_t mpf_inp_str (mpf_ptr, FILE *, int);
  1002. #endif
  1003. #define mpf_integer_p __gmpf_integer_p
  1004. __GMP_DECLSPEC int mpf_integer_p (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1005. #define mpf_mul __gmpf_mul
  1006. __GMP_DECLSPEC void mpf_mul (mpf_ptr, mpf_srcptr, mpf_srcptr);
  1007. #define mpf_mul_2exp __gmpf_mul_2exp
  1008. __GMP_DECLSPEC void mpf_mul_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t);
  1009. #define mpf_mul_ui __gmpf_mul_ui
  1010. __GMP_DECLSPEC void mpf_mul_ui (mpf_ptr, mpf_srcptr, unsigned long int);
  1011. #define mpf_neg __gmpf_neg
  1012. __GMP_DECLSPEC void mpf_neg (mpf_ptr, mpf_srcptr);
  1013. #define mpf_out_str __gmpf_out_str
  1014. #ifdef _GMP_H_HAVE_FILE
  1015. __GMP_DECLSPEC size_t mpf_out_str (FILE *, int, size_t, mpf_srcptr);
  1016. #endif
  1017. #define mpf_pow_ui __gmpf_pow_ui
  1018. __GMP_DECLSPEC void mpf_pow_ui (mpf_ptr, mpf_srcptr, unsigned long int);
  1019. #define mpf_random2 __gmpf_random2
  1020. __GMP_DECLSPEC void mpf_random2 (mpf_ptr, mp_size_t, mp_exp_t);
  1021. #define mpf_reldiff __gmpf_reldiff
  1022. __GMP_DECLSPEC void mpf_reldiff (mpf_ptr, mpf_srcptr, mpf_srcptr);
  1023. #define mpf_set __gmpf_set
  1024. __GMP_DECLSPEC void mpf_set (mpf_ptr, mpf_srcptr);
  1025. #define mpf_set_d __gmpf_set_d
  1026. __GMP_DECLSPEC void mpf_set_d (mpf_ptr, double);
  1027. #define mpf_set_default_prec __gmpf_set_default_prec
  1028. __GMP_DECLSPEC void mpf_set_default_prec (mp_bitcnt_t) __GMP_NOTHROW;
  1029. #define mpf_set_prec __gmpf_set_prec
  1030. __GMP_DECLSPEC void mpf_set_prec (mpf_ptr, mp_bitcnt_t);
  1031. #define mpf_set_prec_raw __gmpf_set_prec_raw
  1032. __GMP_DECLSPEC void mpf_set_prec_raw (mpf_ptr, mp_bitcnt_t) __GMP_NOTHROW;
  1033. #define mpf_set_q __gmpf_set_q
  1034. __GMP_DECLSPEC void mpf_set_q (mpf_ptr, mpq_srcptr);
  1035. #define mpf_set_si __gmpf_set_si
  1036. __GMP_DECLSPEC void mpf_set_si (mpf_ptr, signed long int);
  1037. #define mpf_set_str __gmpf_set_str
  1038. __GMP_DECLSPEC int mpf_set_str (mpf_ptr, const char *, int);
  1039. #define mpf_set_ui __gmpf_set_ui
  1040. __GMP_DECLSPEC void mpf_set_ui (mpf_ptr, unsigned long int);
  1041. #define mpf_set_z __gmpf_set_z
  1042. __GMP_DECLSPEC void mpf_set_z (mpf_ptr, mpz_srcptr);
  1043. #define mpf_size __gmpf_size
  1044. __GMP_DECLSPEC size_t mpf_size (mpf_srcptr) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1045. #define mpf_sqrt __gmpf_sqrt
  1046. __GMP_DECLSPEC void mpf_sqrt (mpf_ptr, mpf_srcptr);
  1047. #define mpf_sqrt_ui __gmpf_sqrt_ui
  1048. __GMP_DECLSPEC void mpf_sqrt_ui (mpf_ptr, unsigned long int);
  1049. #define mpf_sub __gmpf_sub
  1050. __GMP_DECLSPEC void mpf_sub (mpf_ptr, mpf_srcptr, mpf_srcptr);
  1051. #define mpf_sub_ui __gmpf_sub_ui
  1052. __GMP_DECLSPEC void mpf_sub_ui (mpf_ptr, mpf_srcptr, unsigned long int);
  1053. #define mpf_swap __gmpf_swap
  1054. __GMP_DECLSPEC void mpf_swap (mpf_ptr, mpf_ptr) __GMP_NOTHROW;
  1055. #define mpf_trunc __gmpf_trunc
  1056. __GMP_DECLSPEC void mpf_trunc (mpf_ptr, mpf_srcptr);
  1057. #define mpf_ui_div __gmpf_ui_div
  1058. __GMP_DECLSPEC void mpf_ui_div (mpf_ptr, unsigned long int, mpf_srcptr);
  1059. #define mpf_ui_sub __gmpf_ui_sub
  1060. __GMP_DECLSPEC void mpf_ui_sub (mpf_ptr, unsigned long int, mpf_srcptr);
  1061. #define mpf_urandomb __gmpf_urandomb
  1062. __GMP_DECLSPEC void mpf_urandomb (mpf_t, gmp_randstate_t, mp_bitcnt_t);
  1063. /************ Low level positive-integer (i.e. N) routines. ************/
  1064. /* This is ugly, but we need to make user calls reach the prefixed function. */
  1065. #define mpn_add __MPN(add)
  1066. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add)
  1067. __GMP_DECLSPEC mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
  1068. #endif
  1069. #define mpn_add_1 __MPN(add_1)
  1070. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1)
  1071. __GMP_DECLSPEC mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW;
  1072. #endif
  1073. #define mpn_add_n __MPN(add_n)
  1074. __GMP_DECLSPEC mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1075. #define mpn_addmul_1 __MPN(addmul_1)
  1076. __GMP_DECLSPEC mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
  1077. #define mpn_cmp __MPN(cmp)
  1078. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp)
  1079. __GMP_DECLSPEC int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1080. #endif
  1081. #define mpn_zero_p __MPN(zero_p)
  1082. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_zero_p)
  1083. __GMP_DECLSPEC int mpn_zero_p (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1084. #endif
  1085. #define mpn_divexact_1 __MPN(divexact_1)
  1086. __GMP_DECLSPEC void mpn_divexact_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
  1087. #define mpn_divexact_by3(dst,src,size) \
  1088. mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0))
  1089. #define mpn_divexact_by3c __MPN(divexact_by3c)
  1090. __GMP_DECLSPEC mp_limb_t mpn_divexact_by3c (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
  1091. #define mpn_divmod_1(qp,np,nsize,dlimb) \
  1092. mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb)
  1093. #define mpn_divrem __MPN(divrem)
  1094. __GMP_DECLSPEC mp_limb_t mpn_divrem (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t);
  1095. #define mpn_divrem_1 __MPN(divrem_1)
  1096. __GMP_DECLSPEC mp_limb_t mpn_divrem_1 (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t);
  1097. #define mpn_divrem_2 __MPN(divrem_2)
  1098. __GMP_DECLSPEC mp_limb_t mpn_divrem_2 (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr);
  1099. #define mpn_div_qr_1 __MPN(div_qr_1)
  1100. __GMP_DECLSPEC mp_limb_t mpn_div_qr_1 (mp_ptr, mp_limb_t *, mp_srcptr, mp_size_t, mp_limb_t);
  1101. #define mpn_div_qr_2 __MPN(div_qr_2)
  1102. __GMP_DECLSPEC mp_limb_t mpn_div_qr_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr);
  1103. #define mpn_gcd __MPN(gcd)
  1104. __GMP_DECLSPEC mp_size_t mpn_gcd (mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t);
  1105. #define mpn_gcd_11 __MPN(gcd_11)
  1106. __GMP_DECLSPEC mp_limb_t mpn_gcd_11 (mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE;
  1107. #define mpn_gcd_1 __MPN(gcd_1)
  1108. __GMP_DECLSPEC mp_limb_t mpn_gcd_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE;
  1109. #define mpn_gcdext_1 __MPN(gcdext_1)
  1110. __GMP_DECLSPEC mp_limb_t mpn_gcdext_1 (mp_limb_signed_t *, mp_limb_signed_t *, mp_limb_t, mp_limb_t);
  1111. #define mpn_gcdext __MPN(gcdext)
  1112. __GMP_DECLSPEC mp_size_t mpn_gcdext (mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t);
  1113. #define mpn_get_str __MPN(get_str)
  1114. __GMP_DECLSPEC size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t);
  1115. #define mpn_hamdist __MPN(hamdist)
  1116. __GMP_DECLSPEC mp_bitcnt_t mpn_hamdist (mp_srcptr, mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1117. #define mpn_lshift __MPN(lshift)
  1118. __GMP_DECLSPEC mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
  1119. #define mpn_mod_1 __MPN(mod_1)
  1120. __GMP_DECLSPEC mp_limb_t mpn_mod_1 (mp_srcptr, mp_size_t, mp_limb_t) __GMP_ATTRIBUTE_PURE;
  1121. #define mpn_mul __MPN(mul)
  1122. __GMP_DECLSPEC mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
  1123. #define mpn_mul_1 __MPN(mul_1)
  1124. __GMP_DECLSPEC mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
  1125. #define mpn_mul_n __MPN(mul_n)
  1126. __GMP_DECLSPEC void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1127. #define mpn_sqr __MPN(sqr)
  1128. __GMP_DECLSPEC void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);
  1129. #define mpn_neg __MPN(neg)
  1130. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_neg)
  1131. __GMP_DECLSPEC mp_limb_t mpn_neg (mp_ptr, mp_srcptr, mp_size_t);
  1132. #endif
  1133. #define mpn_com __MPN(com)
  1134. __GMP_DECLSPEC void mpn_com (mp_ptr, mp_srcptr, mp_size_t);
  1135. #define mpn_perfect_square_p __MPN(perfect_square_p)
  1136. __GMP_DECLSPEC int mpn_perfect_square_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1137. #define mpn_perfect_power_p __MPN(perfect_power_p)
  1138. __GMP_DECLSPEC int mpn_perfect_power_p (mp_srcptr, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1139. #define mpn_popcount __MPN(popcount)
  1140. __GMP_DECLSPEC mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
  1141. #define mpn_pow_1 __MPN(pow_1)
  1142. __GMP_DECLSPEC mp_size_t mpn_pow_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr);
  1143. /* undocumented now, but retained here for upward compatibility */
  1144. #define mpn_preinv_mod_1 __MPN(preinv_mod_1)
  1145. __GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 (mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t) __GMP_ATTRIBUTE_PURE;
  1146. #define mpn_random __MPN(random)
  1147. __GMP_DECLSPEC void mpn_random (mp_ptr, mp_size_t);
  1148. #define mpn_random2 __MPN(random2)
  1149. __GMP_DECLSPEC void mpn_random2 (mp_ptr, mp_size_t);
  1150. #define mpn_rshift __MPN(rshift)
  1151. __GMP_DECLSPEC mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
  1152. #define mpn_scan0 __MPN(scan0)
  1153. __GMP_DECLSPEC mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE;
  1154. #define mpn_scan1 __MPN(scan1)
  1155. __GMP_DECLSPEC mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t) __GMP_ATTRIBUTE_PURE;
  1156. #define mpn_set_str __MPN(set_str)
  1157. __GMP_DECLSPEC mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int);
  1158. #define mpn_sizeinbase __MPN(sizeinbase)
  1159. __GMP_DECLSPEC size_t mpn_sizeinbase (mp_srcptr, mp_size_t, int);
  1160. #define mpn_sqrtrem __MPN(sqrtrem)
  1161. __GMP_DECLSPEC mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t);
  1162. #define mpn_sub __MPN(sub)
  1163. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub)
  1164. __GMP_DECLSPEC mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
  1165. #endif
  1166. #define mpn_sub_1 __MPN(sub_1)
  1167. #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1)
  1168. __GMP_DECLSPEC mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t) __GMP_NOTHROW;
  1169. #endif
  1170. #define mpn_sub_n __MPN(sub_n)
  1171. __GMP_DECLSPEC mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1172. #define mpn_submul_1 __MPN(submul_1)
  1173. __GMP_DECLSPEC mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
  1174. #define mpn_tdiv_qr __MPN(tdiv_qr)
  1175. __GMP_DECLSPEC void mpn_tdiv_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
  1176. #define mpn_and_n __MPN(and_n)
  1177. __GMP_DECLSPEC void mpn_and_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1178. #define mpn_andn_n __MPN(andn_n)
  1179. __GMP_DECLSPEC void mpn_andn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1180. #define mpn_nand_n __MPN(nand_n)
  1181. __GMP_DECLSPEC void mpn_nand_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1182. #define mpn_ior_n __MPN(ior_n)
  1183. __GMP_DECLSPEC void mpn_ior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1184. #define mpn_iorn_n __MPN(iorn_n)
  1185. __GMP_DECLSPEC void mpn_iorn_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1186. #define mpn_nior_n __MPN(nior_n)
  1187. __GMP_DECLSPEC void mpn_nior_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1188. #define mpn_xor_n __MPN(xor_n)
  1189. __GMP_DECLSPEC void mpn_xor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1190. #define mpn_xnor_n __MPN(xnor_n)
  1191. __GMP_DECLSPEC void mpn_xnor_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1192. #define mpn_copyi __MPN(copyi)
  1193. __GMP_DECLSPEC void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t);
  1194. #define mpn_copyd __MPN(copyd)
  1195. __GMP_DECLSPEC void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);
  1196. #define mpn_zero __MPN(zero)
  1197. __GMP_DECLSPEC void mpn_zero (mp_ptr, mp_size_t);
  1198. #define mpn_cnd_add_n __MPN(cnd_add_n)
  1199. __GMP_DECLSPEC mp_limb_t mpn_cnd_add_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1200. #define mpn_cnd_sub_n __MPN(cnd_sub_n)
  1201. __GMP_DECLSPEC mp_limb_t mpn_cnd_sub_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
  1202. #define mpn_sec_add_1 __MPN(sec_add_1)
  1203. __GMP_DECLSPEC mp_limb_t mpn_sec_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr);
  1204. #define mpn_sec_add_1_itch __MPN(sec_add_1_itch)
  1205. __GMP_DECLSPEC mp_size_t mpn_sec_add_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
  1206. #define mpn_sec_sub_1 __MPN(sec_sub_1)
  1207. __GMP_DECLSPEC mp_limb_t mpn_sec_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr);
  1208. #define mpn_sec_sub_1_itch __MPN(sec_sub_1_itch)
  1209. __GMP_DECLSPEC mp_size_t mpn_sec_sub_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
  1210. #define mpn_cnd_swap __MPN(cnd_swap)
  1211. __GMP_DECLSPEC void mpn_cnd_swap (mp_limb_t, volatile mp_limb_t *, volatile mp_limb_t *, mp_size_t);
  1212. #define mpn_sec_mul __MPN(sec_mul)
  1213. __GMP_DECLSPEC void mpn_sec_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr);
  1214. #define mpn_sec_mul_itch __MPN(sec_mul_itch)
  1215. __GMP_DECLSPEC mp_size_t mpn_sec_mul_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1216. #define mpn_sec_sqr __MPN(sec_sqr)
  1217. __GMP_DECLSPEC void mpn_sec_sqr (mp_ptr, mp_srcptr, mp_size_t, mp_ptr);
  1218. #define mpn_sec_sqr_itch __MPN(sec_sqr_itch)
  1219. __GMP_DECLSPEC mp_size_t mpn_sec_sqr_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
  1220. #define mpn_sec_powm __MPN(sec_powm)
  1221. __GMP_DECLSPEC void mpn_sec_powm (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_bitcnt_t, mp_srcptr, mp_size_t, mp_ptr);
  1222. #define mpn_sec_powm_itch __MPN(sec_powm_itch)
  1223. __GMP_DECLSPEC mp_size_t mpn_sec_powm_itch (mp_size_t, mp_bitcnt_t, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1224. #define mpn_sec_tabselect __MPN(sec_tabselect)
  1225. __GMP_DECLSPEC void mpn_sec_tabselect (volatile mp_limb_t *, volatile const mp_limb_t *, mp_size_t, mp_size_t, mp_size_t);
  1226. #define mpn_sec_div_qr __MPN(sec_div_qr)
  1227. __GMP_DECLSPEC mp_limb_t mpn_sec_div_qr (mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr);
  1228. #define mpn_sec_div_qr_itch __MPN(sec_div_qr_itch)
  1229. __GMP_DECLSPEC mp_size_t mpn_sec_div_qr_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1230. #define mpn_sec_div_r __MPN(sec_div_r)
  1231. __GMP_DECLSPEC void mpn_sec_div_r (mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr);
  1232. #define mpn_sec_div_r_itch __MPN(sec_div_r_itch)
  1233. __GMP_DECLSPEC mp_size_t mpn_sec_div_r_itch (mp_size_t, mp_size_t) __GMP_ATTRIBUTE_PURE;
  1234. #define mpn_sec_invert __MPN(sec_invert)
  1235. __GMP_DECLSPEC int mpn_sec_invert (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_bitcnt_t, mp_ptr);
  1236. #define mpn_sec_invert_itch __MPN(sec_invert_itch)
  1237. __GMP_DECLSPEC mp_size_t mpn_sec_invert_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
  1238. /**************** mpz inlines ****************/
  1239. /* The following are provided as inlines where possible, but always exist as
  1240. library functions too, for binary compatibility.
  1241. Within gmp itself this inlining generally isn't relied on, since it
  1242. doesn't get done for all compilers, whereas if something is worth
  1243. inlining then it's worth arranging always.
  1244. There are two styles of inlining here. When the same bit of code is
  1245. wanted for the inline as for the library version, then __GMP_FORCE_foo
  1246. arranges for that code to be emitted and the __GMP_EXTERN_INLINE
  1247. directive suppressed, eg. mpz_fits_uint_p. When a different bit of code
  1248. is wanted for the inline than for the library version, then
  1249. __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */
  1250. #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs)
  1251. __GMP_EXTERN_INLINE void
  1252. mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u)
  1253. {
  1254. if (__gmp_w != __gmp_u)
  1255. mpz_set (__gmp_w, __gmp_u);
  1256. __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size);
  1257. }
  1258. #endif
  1259. #if GMP_NAIL_BITS == 0
  1260. #define __GMPZ_FITS_UTYPE_P(z,maxval) \
  1261. mp_size_t __gmp_n = z->_mp_size; \
  1262. mp_ptr __gmp_p = z->_mp_d; \
  1263. return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval));
  1264. #else
  1265. #define __GMPZ_FITS_UTYPE_P(z,maxval) \
  1266. mp_size_t __gmp_n = z->_mp_size; \
  1267. mp_ptr __gmp_p = z->_mp_d; \
  1268. return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \
  1269. || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS)));
  1270. #endif
  1271. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p)
  1272. #if ! defined (__GMP_FORCE_mpz_fits_uint_p)
  1273. __GMP_EXTERN_INLINE
  1274. #endif
  1275. int
  1276. mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
  1277. {
  1278. __GMPZ_FITS_UTYPE_P (__gmp_z, UINT_MAX);
  1279. }
  1280. #endif
  1281. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p)
  1282. #if ! defined (__GMP_FORCE_mpz_fits_ulong_p)
  1283. __GMP_EXTERN_INLINE
  1284. #endif
  1285. int
  1286. mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
  1287. {
  1288. __GMPZ_FITS_UTYPE_P (__gmp_z, ULONG_MAX);
  1289. }
  1290. #endif
  1291. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p)
  1292. #if ! defined (__GMP_FORCE_mpz_fits_ushort_p)
  1293. __GMP_EXTERN_INLINE
  1294. #endif
  1295. int
  1296. mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
  1297. {
  1298. __GMPZ_FITS_UTYPE_P (__gmp_z, USHRT_MAX);
  1299. }
  1300. #endif
  1301. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui)
  1302. #if ! defined (__GMP_FORCE_mpz_get_ui)
  1303. __GMP_EXTERN_INLINE
  1304. #endif
  1305. unsigned long
  1306. mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW
  1307. {
  1308. mp_ptr __gmp_p = __gmp_z->_mp_d;
  1309. mp_size_t __gmp_n = __gmp_z->_mp_size;
  1310. mp_limb_t __gmp_l = __gmp_p[0];
  1311. /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings
  1312. about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland
  1313. C++ 6.0 warnings about condition always true for something like
  1314. "ULONG_MAX < GMP_NUMB_MASK". */
  1315. #if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB)
  1316. /* limb==long and no nails, or limb==longlong, one limb is enough */
  1317. return (__gmp_n != 0 ? __gmp_l : 0);
  1318. #else
  1319. /* limb==long and nails, need two limbs when available */
  1320. __gmp_n = __GMP_ABS (__gmp_n);
  1321. if (__gmp_n <= 1)
  1322. return (__gmp_n != 0 ? __gmp_l : 0);
  1323. else
  1324. return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS);
  1325. #endif
  1326. }
  1327. #endif
  1328. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn)
  1329. #if ! defined (__GMP_FORCE_mpz_getlimbn)
  1330. __GMP_EXTERN_INLINE
  1331. #endif
  1332. mp_limb_t
  1333. mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW
  1334. {
  1335. mp_limb_t __gmp_result = 0;
  1336. if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size)))
  1337. __gmp_result = __gmp_z->_mp_d[__gmp_n];
  1338. return __gmp_result;
  1339. }
  1340. #endif
  1341. #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg)
  1342. __GMP_EXTERN_INLINE void
  1343. mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u)
  1344. {
  1345. if (__gmp_w != __gmp_u)
  1346. mpz_set (__gmp_w, __gmp_u);
  1347. __gmp_w->_mp_size = - __gmp_w->_mp_size;
  1348. }
  1349. #endif
  1350. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p)
  1351. #if ! defined (__GMP_FORCE_mpz_perfect_square_p)
  1352. __GMP_EXTERN_INLINE
  1353. #endif
  1354. int
  1355. mpz_perfect_square_p (mpz_srcptr __gmp_a)
  1356. {
  1357. mp_size_t __gmp_asize;
  1358. int __gmp_result;
  1359. __gmp_asize = __gmp_a->_mp_size;
  1360. __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */
  1361. if (__GMP_LIKELY (__gmp_asize > 0))
  1362. __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize);
  1363. return __gmp_result;
  1364. }
  1365. #endif
  1366. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount)
  1367. #if ! defined (__GMP_FORCE_mpz_popcount)
  1368. __GMP_EXTERN_INLINE
  1369. #endif
  1370. mp_bitcnt_t
  1371. mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW
  1372. {
  1373. mp_size_t __gmp_usize;
  1374. mp_bitcnt_t __gmp_result;
  1375. __gmp_usize = __gmp_u->_mp_size;
  1376. __gmp_result = (__gmp_usize < 0 ? ~ __GMP_CAST (mp_bitcnt_t, 0) : __GMP_CAST (mp_bitcnt_t, 0));
  1377. if (__GMP_LIKELY (__gmp_usize > 0))
  1378. __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize);
  1379. return __gmp_result;
  1380. }
  1381. #endif
  1382. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q)
  1383. #if ! defined (__GMP_FORCE_mpz_set_q)
  1384. __GMP_EXTERN_INLINE
  1385. #endif
  1386. void
  1387. mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u)
  1388. {
  1389. mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u));
  1390. }
  1391. #endif
  1392. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size)
  1393. #if ! defined (__GMP_FORCE_mpz_size)
  1394. __GMP_EXTERN_INLINE
  1395. #endif
  1396. size_t
  1397. mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW
  1398. {
  1399. return __GMP_ABS (__gmp_z->_mp_size);
  1400. }
  1401. #endif
  1402. /**************** mpq inlines ****************/
  1403. #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs)
  1404. __GMP_EXTERN_INLINE void
  1405. mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u)
  1406. {
  1407. if (__gmp_w != __gmp_u)
  1408. mpq_set (__gmp_w, __gmp_u);
  1409. __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size);
  1410. }
  1411. #endif
  1412. #if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg)
  1413. __GMP_EXTERN_INLINE void
  1414. mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u)
  1415. {
  1416. if (__gmp_w != __gmp_u)
  1417. mpq_set (__gmp_w, __gmp_u);
  1418. __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size;
  1419. }
  1420. #endif
  1421. /**************** mpn inlines ****************/
  1422. /* The comments with __GMPN_ADD_1 below apply here too.
  1423. The test for FUNCTION returning 0 should predict well. If it's assumed
  1424. {yp,ysize} will usually have a random number of bits then the high limb
  1425. won't be full and a carry out will occur a good deal less than 50% of the
  1426. time.
  1427. ysize==0 isn't a documented feature, but is used internally in a few
  1428. places.
  1429. Producing cout last stops it using up a register during the main part of
  1430. the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))"
  1431. doesn't seem able to move the true and false legs of the conditional up
  1432. to the two places cout is generated. */
  1433. #define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \
  1434. do { \
  1435. mp_size_t __gmp_i; \
  1436. mp_limb_t __gmp_x; \
  1437. \
  1438. /* ASSERT ((ysize) >= 0); */ \
  1439. /* ASSERT ((xsize) >= (ysize)); */ \
  1440. /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \
  1441. /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \
  1442. \
  1443. __gmp_i = (ysize); \
  1444. if (__gmp_i != 0) \
  1445. { \
  1446. if (FUNCTION (wp, xp, yp, __gmp_i)) \
  1447. { \
  1448. do \
  1449. { \
  1450. if (__gmp_i >= (xsize)) \
  1451. { \
  1452. (cout) = 1; \
  1453. goto __gmp_done; \
  1454. } \
  1455. __gmp_x = (xp)[__gmp_i]; \
  1456. } \
  1457. while (TEST); \
  1458. } \
  1459. } \
  1460. if ((wp) != (xp)) \
  1461. __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \
  1462. (cout) = 0; \
  1463. __gmp_done: \
  1464. ; \
  1465. } while (0)
  1466. #define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \
  1467. __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \
  1468. (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0))
  1469. #define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \
  1470. __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \
  1471. (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0))
  1472. /* The use of __gmp_i indexing is designed to ensure a compile time src==dst
  1473. remains nice and clear to the compiler, so that __GMPN_COPY_REST can
  1474. disappear, and the load/add/store gets a chance to become a
  1475. read-modify-write on CISC CPUs.
  1476. Alternatives:
  1477. Using a pair of pointers instead of indexing would be possible, but gcc
  1478. isn't able to recognise compile-time src==dst in that case, even when the
  1479. pointers are incremented more or less together. Other compilers would
  1480. very likely have similar difficulty.
  1481. gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or
  1482. similar to detect a compile-time src==dst. This works nicely on gcc
  1483. 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems
  1484. to be always false, for a pointer p. But the current code form seems
  1485. good enough for src==dst anyway.
  1486. gcc on x86 as usual doesn't give particularly good flags handling for the
  1487. carry/borrow detection. It's tempting to want some multi instruction asm
  1488. blocks to help it, and this was tried, but in truth there's only a few
  1489. instructions to save and any gain is all too easily lost by register
  1490. juggling setting up for the asm. */
  1491. #if GMP_NAIL_BITS == 0
  1492. #define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \
  1493. do { \
  1494. mp_size_t __gmp_i; \
  1495. mp_limb_t __gmp_x, __gmp_r; \
  1496. \
  1497. /* ASSERT ((n) >= 1); */ \
  1498. /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \
  1499. \
  1500. __gmp_x = (src)[0]; \
  1501. __gmp_r = __gmp_x OP (v); \
  1502. (dst)[0] = __gmp_r; \
  1503. if (CB (__gmp_r, __gmp_x, (v))) \
  1504. { \
  1505. (cout) = 1; \
  1506. for (__gmp_i = 1; __gmp_i < (n);) \
  1507. { \
  1508. __gmp_x = (src)[__gmp_i]; \
  1509. __gmp_r = __gmp_x OP 1; \
  1510. (dst)[__gmp_i] = __gmp_r; \
  1511. ++__gmp_i; \
  1512. if (!CB (__gmp_r, __gmp_x, 1)) \
  1513. { \
  1514. if ((src) != (dst)) \
  1515. __GMPN_COPY_REST (dst, src, n, __gmp_i); \
  1516. (cout) = 0; \
  1517. break; \
  1518. } \
  1519. } \
  1520. } \
  1521. else \
  1522. { \
  1523. if ((src) != (dst)) \
  1524. __GMPN_COPY_REST (dst, src, n, 1); \
  1525. (cout) = 0; \
  1526. } \
  1527. } while (0)
  1528. #endif
  1529. #if GMP_NAIL_BITS >= 1
  1530. #define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \
  1531. do { \
  1532. mp_size_t __gmp_i; \
  1533. mp_limb_t __gmp_x, __gmp_r; \
  1534. \
  1535. /* ASSERT ((n) >= 1); */ \
  1536. /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \
  1537. \
  1538. __gmp_x = (src)[0]; \
  1539. __gmp_r = __gmp_x OP (v); \
  1540. (dst)[0] = __gmp_r & GMP_NUMB_MASK; \
  1541. if (__gmp_r >> GMP_NUMB_BITS != 0) \
  1542. { \
  1543. (cout) = 1; \
  1544. for (__gmp_i = 1; __gmp_i < (n);) \
  1545. { \
  1546. __gmp_x = (src)[__gmp_i]; \
  1547. __gmp_r = __gmp_x OP 1; \
  1548. (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \
  1549. ++__gmp_i; \
  1550. if (__gmp_r >> GMP_NUMB_BITS == 0) \
  1551. { \
  1552. if ((src) != (dst)) \
  1553. __GMPN_COPY_REST (dst, src, n, __gmp_i); \
  1554. (cout) = 0; \
  1555. break; \
  1556. } \
  1557. } \
  1558. } \
  1559. else \
  1560. { \
  1561. if ((src) != (dst)) \
  1562. __GMPN_COPY_REST (dst, src, n, 1); \
  1563. (cout) = 0; \
  1564. } \
  1565. } while (0)
  1566. #endif
  1567. #define __GMPN_ADDCB(r,x,y) ((r) < (y))
  1568. #define __GMPN_SUBCB(r,x,y) ((x) < (y))
  1569. #define __GMPN_ADD_1(cout, dst, src, n, v) \
  1570. __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB)
  1571. #define __GMPN_SUB_1(cout, dst, src, n, v) \
  1572. __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB)
  1573. /* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or
  1574. negative. size==0 is allowed. On random data usually only one limb will
  1575. need to be examined to get a result, so it's worth having it inline. */
  1576. #define __GMPN_CMP(result, xp, yp, size) \
  1577. do { \
  1578. mp_size_t __gmp_i; \
  1579. mp_limb_t __gmp_x, __gmp_y; \
  1580. \
  1581. /* ASSERT ((size) >= 0); */ \
  1582. \
  1583. (result) = 0; \
  1584. __gmp_i = (size); \
  1585. while (--__gmp_i >= 0) \
  1586. { \
  1587. __gmp_x = (xp)[__gmp_i]; \
  1588. __gmp_y = (yp)[__gmp_i]; \
  1589. if (__gmp_x != __gmp_y) \
  1590. { \
  1591. /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \
  1592. (result) = (__gmp_x > __gmp_y ? 1 : -1); \
  1593. break; \
  1594. } \
  1595. } \
  1596. } while (0)
  1597. #if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST)
  1598. #define __GMPN_COPY_REST(dst, src, size, start) \
  1599. do { \
  1600. /* ASSERT ((start) >= 0); */ \
  1601. /* ASSERT ((start) <= (size)); */ \
  1602. __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \
  1603. } while (0)
  1604. #endif
  1605. /* Copy {src,size} to {dst,size}, starting at "start". This is designed to
  1606. keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1,
  1607. __GMPN_ADD, etc. */
  1608. #if ! defined (__GMPN_COPY_REST)
  1609. #define __GMPN_COPY_REST(dst, src, size, start) \
  1610. do { \
  1611. mp_size_t __gmp_j; \
  1612. /* ASSERT ((size) >= 0); */ \
  1613. /* ASSERT ((start) >= 0); */ \
  1614. /* ASSERT ((start) <= (size)); */ \
  1615. /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \
  1616. __GMP_CRAY_Pragma ("_CRI ivdep"); \
  1617. for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \
  1618. (dst)[__gmp_j] = (src)[__gmp_j]; \
  1619. } while (0)
  1620. #endif
  1621. /* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use
  1622. mpn_copyi if there's a native version, and if we don't mind demanding
  1623. binary compatibility for it (on targets which use it). */
  1624. #if ! defined (__GMPN_COPY)
  1625. #define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0)
  1626. #endif
  1627. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add)
  1628. #if ! defined (__GMP_FORCE_mpn_add)
  1629. __GMP_EXTERN_INLINE
  1630. #endif
  1631. mp_limb_t
  1632. mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize)
  1633. {
  1634. mp_limb_t __gmp_c;
  1635. __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize);
  1636. return __gmp_c;
  1637. }
  1638. #endif
  1639. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1)
  1640. #if ! defined (__GMP_FORCE_mpn_add_1)
  1641. __GMP_EXTERN_INLINE
  1642. #endif
  1643. mp_limb_t
  1644. mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW
  1645. {
  1646. mp_limb_t __gmp_c;
  1647. __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n);
  1648. return __gmp_c;
  1649. }
  1650. #endif
  1651. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp)
  1652. #if ! defined (__GMP_FORCE_mpn_cmp)
  1653. __GMP_EXTERN_INLINE
  1654. #endif
  1655. int
  1656. mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW
  1657. {
  1658. int __gmp_result;
  1659. __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size);
  1660. return __gmp_result;
  1661. }
  1662. #endif
  1663. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_zero_p)
  1664. #if ! defined (__GMP_FORCE_mpn_zero_p)
  1665. __GMP_EXTERN_INLINE
  1666. #endif
  1667. int
  1668. mpn_zero_p (mp_srcptr __gmp_p, mp_size_t __gmp_n) __GMP_NOTHROW
  1669. {
  1670. /* if (__GMP_LIKELY (__gmp_n > 0)) */
  1671. do {
  1672. if (__gmp_p[--__gmp_n] != 0)
  1673. return 0;
  1674. } while (__gmp_n != 0);
  1675. return 1;
  1676. }
  1677. #endif
  1678. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub)
  1679. #if ! defined (__GMP_FORCE_mpn_sub)
  1680. __GMP_EXTERN_INLINE
  1681. #endif
  1682. mp_limb_t
  1683. mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize)
  1684. {
  1685. mp_limb_t __gmp_c;
  1686. __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize);
  1687. return __gmp_c;
  1688. }
  1689. #endif
  1690. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1)
  1691. #if ! defined (__GMP_FORCE_mpn_sub_1)
  1692. __GMP_EXTERN_INLINE
  1693. #endif
  1694. mp_limb_t
  1695. mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW
  1696. {
  1697. mp_limb_t __gmp_c;
  1698. __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n);
  1699. return __gmp_c;
  1700. }
  1701. #endif
  1702. #if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_neg)
  1703. #if ! defined (__GMP_FORCE_mpn_neg)
  1704. __GMP_EXTERN_INLINE
  1705. #endif
  1706. mp_limb_t
  1707. mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n)
  1708. {
  1709. while (*__gmp_up == 0) /* Low zero limbs are unchanged by negation. */
  1710. {
  1711. *__gmp_rp = 0;
  1712. if (!--__gmp_n) /* All zero */
  1713. return 0;
  1714. ++__gmp_up; ++__gmp_rp;
  1715. }
  1716. *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK;
  1717. if (--__gmp_n) /* Higher limbs get complemented. */
  1718. mpn_com (++__gmp_rp, ++__gmp_up, __gmp_n);
  1719. return 1;
  1720. }
  1721. #endif
  1722. #if defined (__cplusplus)
  1723. }
  1724. #endif
  1725. /* Allow faster testing for negative, zero, and positive. */
  1726. #define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
  1727. #define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
  1728. #define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
  1729. /* When using GCC, optimize certain common comparisons. */
  1730. #if defined (__GNUC__) && __GNUC__ >= 2
  1731. #define mpz_cmp_ui(Z,UI) \
  1732. (__builtin_constant_p (UI) && (UI) == 0 \
  1733. ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI))
  1734. #define mpz_cmp_si(Z,SI) \
  1735. (__builtin_constant_p ((SI) >= 0) && (SI) >= 0 \
  1736. ? mpz_cmp_ui (Z, __GMP_CAST (unsigned long, SI)) \
  1737. : _mpz_cmp_si (Z,SI))
  1738. #define mpq_cmp_ui(Q,NUI,DUI) \
  1739. (__builtin_constant_p (NUI) && (NUI) == 0 ? mpq_sgn (Q) \
  1740. : __builtin_constant_p ((NUI) == (DUI)) && (NUI) == (DUI) \
  1741. ? mpz_cmp (mpq_numref (Q), mpq_denref (Q)) \
  1742. : _mpq_cmp_ui (Q,NUI,DUI))
  1743. #define mpq_cmp_si(q,n,d) \
  1744. (__builtin_constant_p ((n) >= 0) && (n) >= 0 \
  1745. ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \
  1746. : _mpq_cmp_si (q, n, d))
  1747. #else
  1748. #define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI)
  1749. #define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI)
  1750. #define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI)
  1751. #define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d)
  1752. #endif
  1753. /* Using "&" rather than "&&" means these can come out branch-free. Every
  1754. mpz_t has at least one limb allocated, so fetching the low limb is always
  1755. allowed. */
  1756. #define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0]))
  1757. #define mpz_even_p(z) (! mpz_odd_p (z))
  1758. /**************** C++ routines ****************/
  1759. #ifdef __cplusplus
  1760. __GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr);
  1761. __GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr);
  1762. __GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr);
  1763. __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr);
  1764. __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr);
  1765. __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr);
  1766. #endif
  1767. /* Source-level compatibility with GMP 2 and earlier. */
  1768. #define mpn_divmod(qp,np,nsize,dp,dsize) \
  1769. mpn_divrem (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dp, dsize)
  1770. /* Source-level compatibility with GMP 1. */
  1771. #define mpz_mdiv mpz_fdiv_q
  1772. #define mpz_mdivmod mpz_fdiv_qr
  1773. #define mpz_mmod mpz_fdiv_r
  1774. #define mpz_mdiv_ui mpz_fdiv_q_ui
  1775. #define mpz_mdivmod_ui(q,r,n,d) \
  1776. (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
  1777. #define mpz_mmod_ui(r,n,d) \
  1778. (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
  1779. /* Useful synonyms, but not quite compatible with GMP 1. */
  1780. #define mpz_div mpz_fdiv_q
  1781. #define mpz_divmod mpz_fdiv_qr
  1782. #define mpz_div_ui mpz_fdiv_q_ui
  1783. #define mpz_divmod_ui mpz_fdiv_qr_ui
  1784. #define mpz_div_2exp mpz_fdiv_q_2exp
  1785. #define mpz_mod_2exp mpz_fdiv_r_2exp
  1786. enum
  1787. {
  1788. GMP_ERROR_NONE = 0,
  1789. GMP_ERROR_UNSUPPORTED_ARGUMENT = 1,
  1790. GMP_ERROR_DIVISION_BY_ZERO = 2,
  1791. GMP_ERROR_SQRT_OF_NEGATIVE = 4,
  1792. GMP_ERROR_INVALID_ARGUMENT = 8
  1793. };
  1794. /* Define CC and CFLAGS which were used to build this version of GMP */
  1795. #define __GMP_CC "gcc"
  1796. #define __GMP_CFLAGS "-march=x86-64 -mtune=generic -O2 -pipe"
  1797. /* Major version number is the value of __GNU_MP__ too, above. */
  1798. #define __GNU_MP_VERSION 6
  1799. #define __GNU_MP_VERSION_MINOR 2
  1800. #define __GNU_MP_VERSION_PATCHLEVEL 1
  1801. #define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL)
  1802. #define __GMP_H__
  1803. #endif /* __GMP_H__ */