mpfr.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. /* mpfr.h -- Include file for mpfr.
  2. Copyright 1999-2020 Free Software Foundation, Inc.
  3. Contributed by the AriC and Caramba projects, INRIA.
  4. This file is part of the GNU MPFR Library.
  5. The GNU MPFR Library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or (at your
  8. option) any later version.
  9. The GNU MPFR Library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  12. License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
  15. https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
  16. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. #ifndef __MPFR_H
  18. #define __MPFR_H
  19. /* Define MPFR version number */
  20. #define MPFR_VERSION_MAJOR 4
  21. #define MPFR_VERSION_MINOR 1
  22. #define MPFR_VERSION_PATCHLEVEL 0
  23. #define MPFR_VERSION_STRING "4.1.0-p13"
  24. /* User macros:
  25. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  26. with FILE* (auto-detect).
  27. MPFR_USE_INTMAX_T: Define it to make MPFR define functions dealing
  28. with intmax_t (auto-detect).
  29. MPFR_USE_VA_LIST: Define it to make MPFR define functions dealing
  30. with va_list (auto-detect).
  31. MPFR_USE_C99_FEATURE: Define it to 1 to make MPFR support C99-feature
  32. (auto-detect), to 0 to bypass the detection.
  33. MPFR_USE_EXTENSION: Define it to make MPFR use GCC extension to
  34. reduce warnings.
  35. MPFR_USE_NO_MACRO: Define it to make MPFR remove any overriding
  36. function macro.
  37. */
  38. /* Macros dealing with MPFR VERSION */
  39. #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
  40. #define MPFR_VERSION \
  41. MPFR_VERSION_NUM(MPFR_VERSION_MAJOR,MPFR_VERSION_MINOR,MPFR_VERSION_PATCHLEVEL)
  42. #ifndef MPFR_USE_MINI_GMP
  43. #include <gmp.h>
  44. #else
  45. #include <mini-gmp.h>
  46. #endif
  47. /* Avoid some problems with macro expansion if the user defines macros
  48. with the same name as keywords. By convention, identifiers and macro
  49. names starting with mpfr_ are reserved by MPFR. */
  50. typedef void mpfr_void;
  51. typedef int mpfr_int;
  52. typedef unsigned int mpfr_uint;
  53. typedef long mpfr_long;
  54. typedef unsigned long mpfr_ulong;
  55. typedef size_t mpfr_size_t;
  56. /* Global (possibly TLS) flags. Might also be used in an mpfr_t in the
  57. future (there would be room as mpfr_sign_t just needs 1 byte).
  58. TODO: The tests currently assume that the flags fits in an unsigned int;
  59. this should be cleaned up, e.g. by defining a function that outputs the
  60. flags as a string or by using the flags_out function (from tests/tests.c
  61. directly). */
  62. typedef unsigned int mpfr_flags_t;
  63. /* Flags macros (in the public API) */
  64. #define MPFR_FLAGS_UNDERFLOW 1
  65. #define MPFR_FLAGS_OVERFLOW 2
  66. #define MPFR_FLAGS_NAN 4
  67. #define MPFR_FLAGS_INEXACT 8
  68. #define MPFR_FLAGS_ERANGE 16
  69. #define MPFR_FLAGS_DIVBY0 32
  70. #define MPFR_FLAGS_ALL (MPFR_FLAGS_UNDERFLOW | \
  71. MPFR_FLAGS_OVERFLOW | \
  72. MPFR_FLAGS_NAN | \
  73. MPFR_FLAGS_INEXACT | \
  74. MPFR_FLAGS_ERANGE | \
  75. MPFR_FLAGS_DIVBY0)
  76. /* Definition of rounding modes (DON'T USE MPFR_RNDNA!).
  77. Warning! Changing the contents of this enum should be seen as an
  78. interface change since the old and the new types are not compatible
  79. (the integer type compatible with the enumerated type can even change,
  80. see ISO C99, 6.7.2.2#4), and in Makefile.am, AGE should be set to 0.
  81. MPFR_RNDU must appear just before MPFR_RNDD (see
  82. MPFR_IS_RNDUTEST_OR_RNDDNOTTEST in mpfr-impl.h).
  83. If you change the order of the rounding modes, please update the routines
  84. in texceptions.c which assume 0=RNDN, 1=RNDZ, 2=RNDU, 3=RNDD, 4=RNDA.
  85. */
  86. typedef enum {
  87. MPFR_RNDN=0, /* round to nearest, with ties to even */
  88. MPFR_RNDZ, /* round toward zero */
  89. MPFR_RNDU, /* round toward +Inf */
  90. MPFR_RNDD, /* round toward -Inf */
  91. MPFR_RNDA, /* round away from zero */
  92. MPFR_RNDF, /* faithful rounding */
  93. MPFR_RNDNA=-1 /* round to nearest, with ties away from zero (mpfr_round) */
  94. } mpfr_rnd_t;
  95. /* kept for compatibility with MPFR 2.4.x and before */
  96. #define GMP_RNDN MPFR_RNDN
  97. #define GMP_RNDZ MPFR_RNDZ
  98. #define GMP_RNDU MPFR_RNDU
  99. #define GMP_RNDD MPFR_RNDD
  100. /* The _MPFR_PREC_FORMAT and _MPFR_EXP_FORMAT values are automatically
  101. defined below. You MUST NOT force a value (this will break the ABI),
  102. possibly except for a very particular use, in which case you also need
  103. to rebuild the MPFR library with the chosen values; do not install this
  104. rebuilt library in a path that is searched by default, otherwise this
  105. will break applications that are dynamically linked with MPFR.
  106. Using non-default values is not guaranteed to work.
  107. Note: With the following default choices for _MPFR_PREC_FORMAT and
  108. _MPFR_EXP_FORMAT, mpfr_exp_t will be the same as [mp_exp_t] (at least
  109. up to GMP 6). */
  110. /* Define precision: 1 (short), 2 (int) or 3 (long).
  111. DON'T FORCE A VALUE (see above). */
  112. #ifndef _MPFR_PREC_FORMAT
  113. # if __GMP_MP_SIZE_T_INT
  114. # define _MPFR_PREC_FORMAT 2
  115. # else
  116. # define _MPFR_PREC_FORMAT 3
  117. # endif
  118. #endif
  119. /* Define exponent: 1 (short), 2 (int), 3 (long) or 4 (intmax_t).
  120. DON'T FORCE A VALUE (see above). */
  121. #ifndef _MPFR_EXP_FORMAT
  122. # define _MPFR_EXP_FORMAT _MPFR_PREC_FORMAT
  123. #endif
  124. #if _MPFR_PREC_FORMAT > _MPFR_EXP_FORMAT
  125. # error "mpfr_prec_t must not be larger than mpfr_exp_t"
  126. #endif
  127. /* Let's make mpfr_prec_t signed in order to avoid problems due to the
  128. usual arithmetic conversions when mixing mpfr_prec_t and mpfr_exp_t
  129. in an expression (for error analysis) if casts are forgotten.
  130. Note: mpfr_prec_t is currently limited to "long". This means that
  131. under MS Windows, the precisions are limited to about 2^31; however,
  132. these are already huge precisions, probably sufficient in practice
  133. on this platform. */
  134. #if _MPFR_PREC_FORMAT == 1
  135. typedef short mpfr_prec_t;
  136. typedef unsigned short mpfr_uprec_t;
  137. #elif _MPFR_PREC_FORMAT == 2
  138. typedef int mpfr_prec_t;
  139. typedef unsigned int mpfr_uprec_t;
  140. #elif _MPFR_PREC_FORMAT == 3
  141. /* we could use "long long" under Windows 64 here, which can be tested
  142. with the macro _WIN64 according to
  143. https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
  144. typedef long mpfr_prec_t;
  145. typedef unsigned long mpfr_uprec_t;
  146. #else
  147. # error "Invalid MPFR Prec format"
  148. #endif
  149. /* Definition of precision limits without needing <limits.h> */
  150. /* Note: The casts allows the expression to yield the wanted behavior
  151. for _MPFR_PREC_FORMAT == 1 (due to integer promotion rules). We
  152. also make sure that MPFR_PREC_MIN and MPFR_PREC_MAX have a signed
  153. integer type. The "- 256" allows more security, avoiding some
  154. integer overflows in extreme cases; ideally it should be useless. */
  155. #define MPFR_PREC_MIN 1
  156. #define MPFR_PREC_MAX ((mpfr_prec_t) ((((mpfr_uprec_t) -1) >> 1) - 256))
  157. /* Definition of sign */
  158. typedef int mpfr_sign_t;
  159. /* Definition of the exponent. _MPFR_EXP_FORMAT must be large enough
  160. so that mpfr_exp_t has at least 32 bits. */
  161. #if _MPFR_EXP_FORMAT == 1
  162. typedef short mpfr_exp_t;
  163. typedef unsigned short mpfr_uexp_t;
  164. #elif _MPFR_EXP_FORMAT == 2
  165. typedef int mpfr_exp_t;
  166. typedef unsigned int mpfr_uexp_t;
  167. #elif _MPFR_EXP_FORMAT == 3
  168. typedef long mpfr_exp_t;
  169. typedef unsigned long mpfr_uexp_t;
  170. #elif _MPFR_EXP_FORMAT == 4
  171. /* Note: in this case, intmax_t and uintmax_t must be defined before
  172. the inclusion of mpfr.h (we do not include <stdint.h> here because
  173. of some non-ISO C99 implementations that support these types). */
  174. typedef intmax_t mpfr_exp_t;
  175. typedef uintmax_t mpfr_uexp_t;
  176. #else
  177. # error "Invalid MPFR Exp format"
  178. #endif
  179. /* Definition of the standard exponent limits */
  180. #define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((mpfr_ulong) 1 << 30) - 1))
  181. #define MPFR_EMIN_DEFAULT (-(MPFR_EMAX_DEFAULT))
  182. /* DON'T USE THIS! (For MPFR-public macros only, see below.)
  183. The mpfr_sgn macro uses the fact that __MPFR_EXP_NAN and __MPFR_EXP_ZERO
  184. are the smallest values. For a n-bit type, EXP_MAX is 2^(n-1)-1,
  185. EXP_ZERO is 1-2^(n-1), EXP_NAN is 2-2^(n-1), EXP_INF is 3-2^(n-1).
  186. This may change in the future. MPFR code should not be based on these
  187. representations (but if this is absolutely needed, protect the code
  188. with a static assertion). */
  189. #define __MPFR_EXP_MAX ((mpfr_exp_t) (((mpfr_uexp_t) -1) >> 1))
  190. #define __MPFR_EXP_NAN (1 - __MPFR_EXP_MAX)
  191. #define __MPFR_EXP_ZERO (0 - __MPFR_EXP_MAX)
  192. #define __MPFR_EXP_INF (2 - __MPFR_EXP_MAX)
  193. /* Definition of the main structure */
  194. typedef struct {
  195. mpfr_prec_t _mpfr_prec;
  196. mpfr_sign_t _mpfr_sign;
  197. mpfr_exp_t _mpfr_exp;
  198. mp_limb_t *_mpfr_d;
  199. } __mpfr_struct;
  200. /* Compatibility with previous types of MPFR */
  201. #ifndef mp_rnd_t
  202. # define mp_rnd_t mpfr_rnd_t
  203. #endif
  204. #ifndef mp_prec_t
  205. # define mp_prec_t mpfr_prec_t
  206. #endif
  207. /*
  208. The represented number is
  209. _sign*(_d[k-1]/B+_d[k-2]/B^2+...+_d[0]/B^k)*2^_exp
  210. where k=ceil(_mp_prec/GMP_NUMB_BITS) and B=2^GMP_NUMB_BITS.
  211. For the msb (most significant bit) normalized representation, we must have
  212. _d[k-1]>=B/2, unless the number is singular.
  213. We must also have the last k*GMP_NUMB_BITS-_prec bits set to zero.
  214. */
  215. typedef __mpfr_struct mpfr_t[1];
  216. typedef __mpfr_struct *mpfr_ptr;
  217. typedef const __mpfr_struct *mpfr_srcptr;
  218. /* For those who need a direct and fast access to the sign field.
  219. However it is not in the API, thus use it at your own risk: it might
  220. not be supported, or change name, in further versions!
  221. Unfortunately, it must be defined here (instead of MPFR's internal
  222. header file mpfr-impl.h) because it is used by some macros below.
  223. */
  224. #define MPFR_SIGN(x) ((x)->_mpfr_sign)
  225. /* Stack interface */
  226. typedef enum {
  227. MPFR_NAN_KIND = 0,
  228. MPFR_INF_KIND = 1,
  229. MPFR_ZERO_KIND = 2,
  230. MPFR_REGULAR_KIND = 3
  231. } mpfr_kind_t;
  232. /* Free cache policy */
  233. typedef enum {
  234. MPFR_FREE_LOCAL_CACHE = 1, /* 1 << 0 */
  235. MPFR_FREE_GLOBAL_CACHE = 2 /* 1 << 1 */
  236. } mpfr_free_cache_t;
  237. /* GMP defines:
  238. + size_t: Standard size_t
  239. + __GMP_NOTHROW For C++: can't throw .
  240. + __GMP_EXTERN_INLINE Attribute for inline function.
  241. + __GMP_DECLSPEC_EXPORT compiling to go into a DLL
  242. + __GMP_DECLSPEC_IMPORT compiling to go into a application
  243. */
  244. /* Extra MPFR defines */
  245. #define __MPFR_SENTINEL_ATTR
  246. #if defined (__GNUC__)
  247. # if __GNUC__ >= 4
  248. # undef __MPFR_SENTINEL_ATTR
  249. # define __MPFR_SENTINEL_ATTR __attribute__ ((__sentinel__))
  250. # endif
  251. #endif
  252. /* If the user hasn't requested his/her preference
  253. and if the intention of support by the compiler is C99
  254. and if the compiler is known to support the C99 feature
  255. then we can auto-detect the C99 support as OK.
  256. __GNUC__ is used to detect GNU-C, ICC & CLANG compilers.
  257. Currently we need only variadic macros, and they are present
  258. since GCC >= 3. We don't test library version since we don't
  259. use any feature present in the library too (except intmax_t,
  260. but they use another detection).*/
  261. #ifndef MPFR_USE_C99_FEATURE
  262. # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  263. # if defined (__GNUC__)
  264. # if __GNUC__ >= 3
  265. # define MPFR_USE_C99_FEATURE 1
  266. # endif
  267. # endif
  268. # endif
  269. # ifndef MPFR_USE_C99_FEATURE
  270. # define MPFR_USE_C99_FEATURE 0
  271. # endif
  272. #endif
  273. /* Support for WINDOWS Dll:
  274. Check if we are inside a MPFR build, and if so export the functions.
  275. Otherwise does the same thing as GMP */
  276. #if defined(__MPFR_WITHIN_MPFR) && __GMP_LIBGMP_DLL
  277. # define __MPFR_DECLSPEC __GMP_DECLSPEC_EXPORT
  278. #else
  279. # ifndef __GMP_DECLSPEC
  280. # define __GMP_DECLSPEC
  281. # endif
  282. # define __MPFR_DECLSPEC __GMP_DECLSPEC
  283. #endif
  284. /* Use MPFR_DEPRECATED to mark MPFR functions, types or variables as
  285. deprecated. Code inspired by Apache Subversion's svn_types.h file.
  286. For compatibility with MSVC, MPFR_DEPRECATED must be put before
  287. __MPFR_DECLSPEC (not at the end of the function declaration as
  288. documented in the GCC manual); GCC does not seem to care.
  289. Moreover, in order to avoid a warning when testing such functions,
  290. do something like:
  291. +------------------------------------------
  292. |#ifndef _MPFR_NO_DEPRECATED_funcname
  293. |MPFR_DEPRECATED
  294. |#endif
  295. |__MPFR_DECLSPEC int mpfr_funcname (...);
  296. +------------------------------------------
  297. and in the corresponding test program:
  298. +------------------------------------------
  299. |#define _MPFR_NO_DEPRECATED_funcname
  300. |#include "mpfr-test.h"
  301. +------------------------------------------
  302. */
  303. #if defined(__GNUC__) && \
  304. (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  305. # define MPFR_DEPRECATED __attribute__ ((__deprecated__))
  306. #elif defined(_MSC_VER) && _MSC_VER >= 1300
  307. # define MPFR_DEPRECATED __declspec(deprecated)
  308. #else
  309. # define MPFR_DEPRECATED
  310. #endif
  311. /* TODO: Also define MPFR_EXPERIMENTAL for experimental functions?
  312. See SVN_EXPERIMENTAL in Subversion 1.9+ as an example:
  313. __attribute__((__warning__("..."))) can be used with GCC 4.3.1+ but
  314. not __llvm__, and __declspec(deprecated("...")) can be used with
  315. MSC as above. */
  316. #if defined(__GNUC__) && \
  317. (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))
  318. # define MPFR_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
  319. #else
  320. # define MPFR_RETURNS_NONNULL
  321. #endif
  322. /* Note: In order to be declared, some functions need a specific
  323. system header to be included *before* "mpfr.h". If the user
  324. forgets to include the header, the MPFR function prototype in
  325. the user object file is not correct. To avoid wrong results,
  326. we raise a linker error in that case by changing their internal
  327. name in the library (prefixed by __gmpfr instead of mpfr). See
  328. the lines of the form "#define mpfr_xxx __gmpfr_xxx" below. */
  329. #if defined (__cplusplus)
  330. extern "C" {
  331. #endif
  332. __MPFR_DECLSPEC MPFR_RETURNS_NONNULL const char * mpfr_get_version (void);
  333. __MPFR_DECLSPEC MPFR_RETURNS_NONNULL const char * mpfr_get_patches (void);
  334. __MPFR_DECLSPEC int mpfr_buildopt_tls_p (void);
  335. __MPFR_DECLSPEC int mpfr_buildopt_float128_p (void);
  336. __MPFR_DECLSPEC int mpfr_buildopt_decimal_p (void);
  337. __MPFR_DECLSPEC int mpfr_buildopt_gmpinternals_p (void);
  338. __MPFR_DECLSPEC int mpfr_buildopt_sharedcache_p (void);
  339. __MPFR_DECLSPEC MPFR_RETURNS_NONNULL const char *
  340. mpfr_buildopt_tune_case (void);
  341. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin (void);
  342. __MPFR_DECLSPEC int mpfr_set_emin (mpfr_exp_t);
  343. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_min (void);
  344. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_max (void);
  345. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax (void);
  346. __MPFR_DECLSPEC int mpfr_set_emax (mpfr_exp_t);
  347. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_min (void);
  348. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_max (void);
  349. __MPFR_DECLSPEC void mpfr_set_default_rounding_mode (mpfr_rnd_t);
  350. __MPFR_DECLSPEC mpfr_rnd_t mpfr_get_default_rounding_mode (void);
  351. __MPFR_DECLSPEC const char * mpfr_print_rnd_mode (mpfr_rnd_t);
  352. __MPFR_DECLSPEC void mpfr_clear_flags (void);
  353. __MPFR_DECLSPEC void mpfr_clear_underflow (void);
  354. __MPFR_DECLSPEC void mpfr_clear_overflow (void);
  355. __MPFR_DECLSPEC void mpfr_clear_divby0 (void);
  356. __MPFR_DECLSPEC void mpfr_clear_nanflag (void);
  357. __MPFR_DECLSPEC void mpfr_clear_inexflag (void);
  358. __MPFR_DECLSPEC void mpfr_clear_erangeflag (void);
  359. __MPFR_DECLSPEC void mpfr_set_underflow (void);
  360. __MPFR_DECLSPEC void mpfr_set_overflow (void);
  361. __MPFR_DECLSPEC void mpfr_set_divby0 (void);
  362. __MPFR_DECLSPEC void mpfr_set_nanflag (void);
  363. __MPFR_DECLSPEC void mpfr_set_inexflag (void);
  364. __MPFR_DECLSPEC void mpfr_set_erangeflag (void);
  365. __MPFR_DECLSPEC int mpfr_underflow_p (void);
  366. __MPFR_DECLSPEC int mpfr_overflow_p (void);
  367. __MPFR_DECLSPEC int mpfr_divby0_p (void);
  368. __MPFR_DECLSPEC int mpfr_nanflag_p (void);
  369. __MPFR_DECLSPEC int mpfr_inexflag_p (void);
  370. __MPFR_DECLSPEC int mpfr_erangeflag_p (void);
  371. __MPFR_DECLSPEC void mpfr_flags_clear (mpfr_flags_t);
  372. __MPFR_DECLSPEC void mpfr_flags_set (mpfr_flags_t);
  373. __MPFR_DECLSPEC mpfr_flags_t mpfr_flags_test (mpfr_flags_t);
  374. __MPFR_DECLSPEC mpfr_flags_t mpfr_flags_save (void);
  375. __MPFR_DECLSPEC void mpfr_flags_restore (mpfr_flags_t,
  376. mpfr_flags_t);
  377. __MPFR_DECLSPEC int mpfr_check_range (mpfr_ptr, int, mpfr_rnd_t);
  378. __MPFR_DECLSPEC void mpfr_init2 (mpfr_ptr, mpfr_prec_t);
  379. __MPFR_DECLSPEC void mpfr_init (mpfr_ptr);
  380. __MPFR_DECLSPEC void mpfr_clear (mpfr_ptr);
  381. __MPFR_DECLSPEC void
  382. mpfr_inits2 (mpfr_prec_t, mpfr_ptr, ...) __MPFR_SENTINEL_ATTR;
  383. __MPFR_DECLSPEC void
  384. mpfr_inits (mpfr_ptr, ...) __MPFR_SENTINEL_ATTR;
  385. __MPFR_DECLSPEC void
  386. mpfr_clears (mpfr_ptr, ...) __MPFR_SENTINEL_ATTR;
  387. __MPFR_DECLSPEC int mpfr_prec_round (mpfr_ptr, mpfr_prec_t, mpfr_rnd_t);
  388. __MPFR_DECLSPEC int mpfr_can_round (mpfr_srcptr, mpfr_exp_t, mpfr_rnd_t,
  389. mpfr_rnd_t, mpfr_prec_t);
  390. __MPFR_DECLSPEC mpfr_prec_t mpfr_min_prec (mpfr_srcptr);
  391. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_exp (mpfr_srcptr);
  392. __MPFR_DECLSPEC int mpfr_set_exp (mpfr_ptr, mpfr_exp_t);
  393. __MPFR_DECLSPEC mpfr_prec_t mpfr_get_prec (mpfr_srcptr);
  394. __MPFR_DECLSPEC void mpfr_set_prec (mpfr_ptr, mpfr_prec_t);
  395. __MPFR_DECLSPEC void mpfr_set_prec_raw (mpfr_ptr, mpfr_prec_t);
  396. __MPFR_DECLSPEC void mpfr_set_default_prec (mpfr_prec_t);
  397. __MPFR_DECLSPEC mpfr_prec_t mpfr_get_default_prec (void);
  398. __MPFR_DECLSPEC int mpfr_set_d (mpfr_ptr, double, mpfr_rnd_t);
  399. __MPFR_DECLSPEC int mpfr_set_flt (mpfr_ptr, float, mpfr_rnd_t);
  400. #ifdef MPFR_WANT_DECIMAL_FLOATS
  401. /* _Decimal64 is not defined in C++,
  402. cf https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51364 */
  403. __MPFR_DECLSPEC int mpfr_set_decimal64 (mpfr_ptr, _Decimal64, mpfr_rnd_t);
  404. __MPFR_DECLSPEC int mpfr_set_decimal128 (mpfr_ptr, _Decimal128, mpfr_rnd_t);
  405. #endif
  406. __MPFR_DECLSPEC int mpfr_set_ld (mpfr_ptr, long double, mpfr_rnd_t);
  407. #ifdef MPFR_WANT_FLOAT128
  408. __MPFR_DECLSPEC int mpfr_set_float128 (mpfr_ptr, _Float128, mpfr_rnd_t);
  409. __MPFR_DECLSPEC _Float128 mpfr_get_float128 (mpfr_srcptr, mpfr_rnd_t);
  410. #endif
  411. __MPFR_DECLSPEC int mpfr_set_z (mpfr_ptr, mpz_srcptr, mpfr_rnd_t);
  412. __MPFR_DECLSPEC int mpfr_set_z_2exp (mpfr_ptr, mpz_srcptr, mpfr_exp_t,
  413. mpfr_rnd_t);
  414. __MPFR_DECLSPEC void mpfr_set_nan (mpfr_ptr);
  415. __MPFR_DECLSPEC void mpfr_set_inf (mpfr_ptr, int);
  416. __MPFR_DECLSPEC void mpfr_set_zero (mpfr_ptr, int);
  417. #ifndef MPFR_USE_MINI_GMP
  418. /* mini-gmp does not provide mpf_t, we disable the following functions */
  419. __MPFR_DECLSPEC int mpfr_set_f (mpfr_ptr, mpf_srcptr, mpfr_rnd_t);
  420. __MPFR_DECLSPEC int mpfr_cmp_f (mpfr_srcptr, mpf_srcptr);
  421. __MPFR_DECLSPEC int mpfr_get_f (mpf_ptr, mpfr_srcptr, mpfr_rnd_t);
  422. #endif
  423. __MPFR_DECLSPEC int mpfr_set_si (mpfr_ptr, long, mpfr_rnd_t);
  424. __MPFR_DECLSPEC int mpfr_set_ui (mpfr_ptr, unsigned long, mpfr_rnd_t);
  425. __MPFR_DECLSPEC int mpfr_set_si_2exp (mpfr_ptr, long, mpfr_exp_t, mpfr_rnd_t);
  426. __MPFR_DECLSPEC int mpfr_set_ui_2exp (mpfr_ptr, unsigned long, mpfr_exp_t,
  427. mpfr_rnd_t);
  428. #ifndef MPFR_USE_MINI_GMP
  429. /* mini-gmp does not provide mpq_t, we disable the following functions */
  430. __MPFR_DECLSPEC int mpfr_set_q (mpfr_ptr, mpq_srcptr, mpfr_rnd_t);
  431. __MPFR_DECLSPEC int mpfr_mul_q (mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t);
  432. __MPFR_DECLSPEC int mpfr_div_q (mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t);
  433. __MPFR_DECLSPEC int mpfr_add_q (mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t);
  434. __MPFR_DECLSPEC int mpfr_sub_q (mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t);
  435. __MPFR_DECLSPEC int mpfr_cmp_q (mpfr_srcptr, mpq_srcptr);
  436. __MPFR_DECLSPEC void mpfr_get_q (mpq_ptr q, mpfr_srcptr f);
  437. #endif
  438. __MPFR_DECLSPEC int mpfr_set_str (mpfr_ptr, const char *, int, mpfr_rnd_t);
  439. __MPFR_DECLSPEC int mpfr_init_set_str (mpfr_ptr, const char *, int,
  440. mpfr_rnd_t);
  441. __MPFR_DECLSPEC int mpfr_set4 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int);
  442. __MPFR_DECLSPEC int mpfr_abs (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  443. __MPFR_DECLSPEC int mpfr_set (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  444. __MPFR_DECLSPEC int mpfr_neg (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  445. __MPFR_DECLSPEC int mpfr_signbit (mpfr_srcptr);
  446. __MPFR_DECLSPEC int mpfr_setsign (mpfr_ptr, mpfr_srcptr, int, mpfr_rnd_t);
  447. __MPFR_DECLSPEC int mpfr_copysign (mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
  448. mpfr_rnd_t);
  449. __MPFR_DECLSPEC mpfr_exp_t mpfr_get_z_2exp (mpz_ptr, mpfr_srcptr);
  450. __MPFR_DECLSPEC float mpfr_get_flt (mpfr_srcptr, mpfr_rnd_t);
  451. __MPFR_DECLSPEC double mpfr_get_d (mpfr_srcptr, mpfr_rnd_t);
  452. #ifdef MPFR_WANT_DECIMAL_FLOATS
  453. __MPFR_DECLSPEC _Decimal64 mpfr_get_decimal64 (mpfr_srcptr, mpfr_rnd_t);
  454. __MPFR_DECLSPEC _Decimal128 mpfr_get_decimal128 (mpfr_srcptr, mpfr_rnd_t);
  455. #endif
  456. __MPFR_DECLSPEC long double mpfr_get_ld (mpfr_srcptr, mpfr_rnd_t);
  457. __MPFR_DECLSPEC double mpfr_get_d1 (mpfr_srcptr);
  458. __MPFR_DECLSPEC double mpfr_get_d_2exp (long*, mpfr_srcptr, mpfr_rnd_t);
  459. __MPFR_DECLSPEC long double mpfr_get_ld_2exp (long*, mpfr_srcptr, mpfr_rnd_t);
  460. __MPFR_DECLSPEC int mpfr_frexp (mpfr_exp_t*, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  461. __MPFR_DECLSPEC long mpfr_get_si (mpfr_srcptr, mpfr_rnd_t);
  462. __MPFR_DECLSPEC unsigned long mpfr_get_ui (mpfr_srcptr, mpfr_rnd_t);
  463. __MPFR_DECLSPEC size_t mpfr_get_str_ndigits (int, mpfr_prec_t);
  464. __MPFR_DECLSPEC char * mpfr_get_str (char*, mpfr_exp_t*, int, size_t,
  465. mpfr_srcptr, mpfr_rnd_t);
  466. __MPFR_DECLSPEC int mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t);
  467. __MPFR_DECLSPEC void mpfr_free_str (char *);
  468. __MPFR_DECLSPEC int mpfr_urandom (mpfr_ptr, gmp_randstate_t, mpfr_rnd_t);
  469. #ifndef _MPFR_NO_DEPRECATED_GRANDOM /* for the test of this function */
  470. MPFR_DEPRECATED
  471. #endif
  472. __MPFR_DECLSPEC int mpfr_grandom (mpfr_ptr, mpfr_ptr, gmp_randstate_t,
  473. mpfr_rnd_t);
  474. __MPFR_DECLSPEC int mpfr_nrandom (mpfr_ptr, gmp_randstate_t, mpfr_rnd_t);
  475. __MPFR_DECLSPEC int mpfr_erandom (mpfr_ptr, gmp_randstate_t, mpfr_rnd_t);
  476. __MPFR_DECLSPEC int mpfr_urandomb (mpfr_ptr, gmp_randstate_t);
  477. __MPFR_DECLSPEC void mpfr_nextabove (mpfr_ptr);
  478. __MPFR_DECLSPEC void mpfr_nextbelow (mpfr_ptr);
  479. __MPFR_DECLSPEC void mpfr_nexttoward (mpfr_ptr, mpfr_srcptr);
  480. #ifndef MPFR_USE_MINI_GMP
  481. __MPFR_DECLSPEC int mpfr_printf (const char*, ...);
  482. __MPFR_DECLSPEC int mpfr_asprintf (char**, const char*, ...);
  483. __MPFR_DECLSPEC int mpfr_sprintf (char*, const char*, ...);
  484. __MPFR_DECLSPEC int mpfr_snprintf (char*, size_t, const char*, ...);
  485. #endif
  486. __MPFR_DECLSPEC int mpfr_pow (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  487. __MPFR_DECLSPEC int mpfr_pow_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  488. __MPFR_DECLSPEC int mpfr_pow_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  489. mpfr_rnd_t);
  490. __MPFR_DECLSPEC int mpfr_ui_pow_ui (mpfr_ptr, unsigned long, unsigned long,
  491. mpfr_rnd_t);
  492. __MPFR_DECLSPEC int mpfr_ui_pow (mpfr_ptr, unsigned long, mpfr_srcptr,
  493. mpfr_rnd_t);
  494. __MPFR_DECLSPEC int mpfr_pow_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);
  495. __MPFR_DECLSPEC int mpfr_sqrt (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  496. __MPFR_DECLSPEC int mpfr_sqrt_ui (mpfr_ptr, unsigned long, mpfr_rnd_t);
  497. __MPFR_DECLSPEC int mpfr_rec_sqrt (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  498. __MPFR_DECLSPEC int mpfr_add (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  499. __MPFR_DECLSPEC int mpfr_sub (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  500. __MPFR_DECLSPEC int mpfr_mul (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  501. __MPFR_DECLSPEC int mpfr_div (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  502. __MPFR_DECLSPEC int mpfr_add_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  503. mpfr_rnd_t);
  504. __MPFR_DECLSPEC int mpfr_sub_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  505. mpfr_rnd_t);
  506. __MPFR_DECLSPEC int mpfr_ui_sub (mpfr_ptr, unsigned long, mpfr_srcptr,
  507. mpfr_rnd_t);
  508. __MPFR_DECLSPEC int mpfr_mul_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  509. mpfr_rnd_t);
  510. __MPFR_DECLSPEC int mpfr_div_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  511. mpfr_rnd_t);
  512. __MPFR_DECLSPEC int mpfr_ui_div (mpfr_ptr, unsigned long, mpfr_srcptr,
  513. mpfr_rnd_t);
  514. __MPFR_DECLSPEC int mpfr_add_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  515. __MPFR_DECLSPEC int mpfr_sub_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  516. __MPFR_DECLSPEC int mpfr_si_sub (mpfr_ptr, long, mpfr_srcptr, mpfr_rnd_t);
  517. __MPFR_DECLSPEC int mpfr_mul_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  518. __MPFR_DECLSPEC int mpfr_div_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  519. __MPFR_DECLSPEC int mpfr_si_div (mpfr_ptr, long, mpfr_srcptr, mpfr_rnd_t);
  520. __MPFR_DECLSPEC int mpfr_add_d (mpfr_ptr, mpfr_srcptr, double, mpfr_rnd_t);
  521. __MPFR_DECLSPEC int mpfr_sub_d (mpfr_ptr, mpfr_srcptr, double, mpfr_rnd_t);
  522. __MPFR_DECLSPEC int mpfr_d_sub (mpfr_ptr, double, mpfr_srcptr, mpfr_rnd_t);
  523. __MPFR_DECLSPEC int mpfr_mul_d (mpfr_ptr, mpfr_srcptr, double, mpfr_rnd_t);
  524. __MPFR_DECLSPEC int mpfr_div_d (mpfr_ptr, mpfr_srcptr, double, mpfr_rnd_t);
  525. __MPFR_DECLSPEC int mpfr_d_div (mpfr_ptr, double, mpfr_srcptr, mpfr_rnd_t);
  526. __MPFR_DECLSPEC int mpfr_sqr (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  527. __MPFR_DECLSPEC int mpfr_const_pi (mpfr_ptr, mpfr_rnd_t);
  528. __MPFR_DECLSPEC int mpfr_const_log2 (mpfr_ptr, mpfr_rnd_t);
  529. __MPFR_DECLSPEC int mpfr_const_euler (mpfr_ptr, mpfr_rnd_t);
  530. __MPFR_DECLSPEC int mpfr_const_catalan (mpfr_ptr, mpfr_rnd_t);
  531. __MPFR_DECLSPEC int mpfr_agm (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  532. __MPFR_DECLSPEC int mpfr_log (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  533. __MPFR_DECLSPEC int mpfr_log2 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  534. __MPFR_DECLSPEC int mpfr_log10 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  535. __MPFR_DECLSPEC int mpfr_log1p (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  536. __MPFR_DECLSPEC int mpfr_log_ui (mpfr_ptr, unsigned long, mpfr_rnd_t);
  537. __MPFR_DECLSPEC int mpfr_exp (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  538. __MPFR_DECLSPEC int mpfr_exp2 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  539. __MPFR_DECLSPEC int mpfr_exp10 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  540. __MPFR_DECLSPEC int mpfr_expm1 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  541. __MPFR_DECLSPEC int mpfr_eint (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  542. __MPFR_DECLSPEC int mpfr_li2 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  543. __MPFR_DECLSPEC int mpfr_cmp (mpfr_srcptr, mpfr_srcptr);
  544. __MPFR_DECLSPEC int mpfr_cmp3 (mpfr_srcptr, mpfr_srcptr, int);
  545. __MPFR_DECLSPEC int mpfr_cmp_d (mpfr_srcptr, double);
  546. __MPFR_DECLSPEC int mpfr_cmp_ld (mpfr_srcptr, long double);
  547. __MPFR_DECLSPEC int mpfr_cmp_ui (mpfr_srcptr, unsigned long);
  548. __MPFR_DECLSPEC int mpfr_cmp_si (mpfr_srcptr, long);
  549. __MPFR_DECLSPEC int mpfr_cmp_ui_2exp (mpfr_srcptr, unsigned long, mpfr_exp_t);
  550. __MPFR_DECLSPEC int mpfr_cmp_si_2exp (mpfr_srcptr, long, mpfr_exp_t);
  551. __MPFR_DECLSPEC int mpfr_cmpabs (mpfr_srcptr, mpfr_srcptr);
  552. __MPFR_DECLSPEC int mpfr_cmpabs_ui (mpfr_srcptr, unsigned long);
  553. __MPFR_DECLSPEC void mpfr_reldiff (mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
  554. mpfr_rnd_t);
  555. __MPFR_DECLSPEC int mpfr_eq (mpfr_srcptr, mpfr_srcptr, unsigned long);
  556. __MPFR_DECLSPEC int mpfr_sgn (mpfr_srcptr);
  557. __MPFR_DECLSPEC int mpfr_mul_2exp (mpfr_ptr, mpfr_srcptr, unsigned long,
  558. mpfr_rnd_t);
  559. __MPFR_DECLSPEC int mpfr_div_2exp (mpfr_ptr, mpfr_srcptr, unsigned long,
  560. mpfr_rnd_t);
  561. __MPFR_DECLSPEC int mpfr_mul_2ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  562. mpfr_rnd_t);
  563. __MPFR_DECLSPEC int mpfr_div_2ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  564. mpfr_rnd_t);
  565. __MPFR_DECLSPEC int mpfr_mul_2si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  566. __MPFR_DECLSPEC int mpfr_div_2si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
  567. __MPFR_DECLSPEC int mpfr_rint (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  568. __MPFR_DECLSPEC int mpfr_roundeven (mpfr_ptr, mpfr_srcptr);
  569. __MPFR_DECLSPEC int mpfr_round (mpfr_ptr, mpfr_srcptr);
  570. __MPFR_DECLSPEC int mpfr_trunc (mpfr_ptr, mpfr_srcptr);
  571. __MPFR_DECLSPEC int mpfr_ceil (mpfr_ptr, mpfr_srcptr);
  572. __MPFR_DECLSPEC int mpfr_floor (mpfr_ptr, mpfr_srcptr);
  573. __MPFR_DECLSPEC int mpfr_rint_roundeven (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  574. __MPFR_DECLSPEC int mpfr_rint_round (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  575. __MPFR_DECLSPEC int mpfr_rint_trunc (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  576. __MPFR_DECLSPEC int mpfr_rint_ceil (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  577. __MPFR_DECLSPEC int mpfr_rint_floor (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  578. __MPFR_DECLSPEC int mpfr_frac (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  579. __MPFR_DECLSPEC int mpfr_modf (mpfr_ptr, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  580. __MPFR_DECLSPEC int mpfr_remquo (mpfr_ptr, long*, mpfr_srcptr, mpfr_srcptr,
  581. mpfr_rnd_t);
  582. __MPFR_DECLSPEC int mpfr_remainder (mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
  583. mpfr_rnd_t);
  584. __MPFR_DECLSPEC int mpfr_fmod (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  585. __MPFR_DECLSPEC int mpfr_fmodquo (mpfr_ptr, long*, mpfr_srcptr, mpfr_srcptr,
  586. mpfr_rnd_t);
  587. __MPFR_DECLSPEC int mpfr_fits_ulong_p (mpfr_srcptr, mpfr_rnd_t);
  588. __MPFR_DECLSPEC int mpfr_fits_slong_p (mpfr_srcptr, mpfr_rnd_t);
  589. __MPFR_DECLSPEC int mpfr_fits_uint_p (mpfr_srcptr, mpfr_rnd_t);
  590. __MPFR_DECLSPEC int mpfr_fits_sint_p (mpfr_srcptr, mpfr_rnd_t);
  591. __MPFR_DECLSPEC int mpfr_fits_ushort_p (mpfr_srcptr, mpfr_rnd_t);
  592. __MPFR_DECLSPEC int mpfr_fits_sshort_p (mpfr_srcptr, mpfr_rnd_t);
  593. __MPFR_DECLSPEC int mpfr_fits_uintmax_p (mpfr_srcptr, mpfr_rnd_t);
  594. __MPFR_DECLSPEC int mpfr_fits_intmax_p (mpfr_srcptr, mpfr_rnd_t);
  595. __MPFR_DECLSPEC void mpfr_extract (mpz_ptr, mpfr_srcptr, unsigned int);
  596. __MPFR_DECLSPEC void mpfr_swap (mpfr_ptr, mpfr_ptr);
  597. __MPFR_DECLSPEC void mpfr_dump (mpfr_srcptr);
  598. __MPFR_DECLSPEC int mpfr_nan_p (mpfr_srcptr);
  599. __MPFR_DECLSPEC int mpfr_inf_p (mpfr_srcptr);
  600. __MPFR_DECLSPEC int mpfr_number_p (mpfr_srcptr);
  601. __MPFR_DECLSPEC int mpfr_integer_p (mpfr_srcptr);
  602. __MPFR_DECLSPEC int mpfr_zero_p (mpfr_srcptr);
  603. __MPFR_DECLSPEC int mpfr_regular_p (mpfr_srcptr);
  604. __MPFR_DECLSPEC int mpfr_greater_p (mpfr_srcptr, mpfr_srcptr);
  605. __MPFR_DECLSPEC int mpfr_greaterequal_p (mpfr_srcptr, mpfr_srcptr);
  606. __MPFR_DECLSPEC int mpfr_less_p (mpfr_srcptr, mpfr_srcptr);
  607. __MPFR_DECLSPEC int mpfr_lessequal_p (mpfr_srcptr, mpfr_srcptr);
  608. __MPFR_DECLSPEC int mpfr_lessgreater_p (mpfr_srcptr, mpfr_srcptr);
  609. __MPFR_DECLSPEC int mpfr_equal_p (mpfr_srcptr, mpfr_srcptr);
  610. __MPFR_DECLSPEC int mpfr_unordered_p (mpfr_srcptr, mpfr_srcptr);
  611. __MPFR_DECLSPEC int mpfr_atanh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  612. __MPFR_DECLSPEC int mpfr_acosh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  613. __MPFR_DECLSPEC int mpfr_asinh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  614. __MPFR_DECLSPEC int mpfr_cosh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  615. __MPFR_DECLSPEC int mpfr_sinh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  616. __MPFR_DECLSPEC int mpfr_tanh (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  617. __MPFR_DECLSPEC int mpfr_sinh_cosh (mpfr_ptr, mpfr_ptr, mpfr_srcptr,
  618. mpfr_rnd_t);
  619. __MPFR_DECLSPEC int mpfr_sech (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  620. __MPFR_DECLSPEC int mpfr_csch (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  621. __MPFR_DECLSPEC int mpfr_coth (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  622. __MPFR_DECLSPEC int mpfr_acos (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  623. __MPFR_DECLSPEC int mpfr_asin (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  624. __MPFR_DECLSPEC int mpfr_atan (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  625. __MPFR_DECLSPEC int mpfr_sin (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  626. __MPFR_DECLSPEC int mpfr_sin_cos (mpfr_ptr, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  627. __MPFR_DECLSPEC int mpfr_cos (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  628. __MPFR_DECLSPEC int mpfr_tan (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  629. __MPFR_DECLSPEC int mpfr_atan2 (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  630. __MPFR_DECLSPEC int mpfr_sec (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  631. __MPFR_DECLSPEC int mpfr_csc (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  632. __MPFR_DECLSPEC int mpfr_cot (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  633. __MPFR_DECLSPEC int mpfr_hypot (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  634. __MPFR_DECLSPEC int mpfr_erf (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  635. __MPFR_DECLSPEC int mpfr_erfc (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  636. __MPFR_DECLSPEC int mpfr_cbrt (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  637. #ifndef _MPFR_NO_DEPRECATED_ROOT /* for the test of this function */
  638. MPFR_DEPRECATED
  639. #endif
  640. __MPFR_DECLSPEC int mpfr_root (mpfr_ptr, mpfr_srcptr, unsigned long,
  641. mpfr_rnd_t);
  642. __MPFR_DECLSPEC int mpfr_rootn_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
  643. mpfr_rnd_t);
  644. __MPFR_DECLSPEC int mpfr_gamma (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  645. __MPFR_DECLSPEC int mpfr_gamma_inc (mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
  646. mpfr_rnd_t);
  647. __MPFR_DECLSPEC int mpfr_beta (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  648. __MPFR_DECLSPEC int mpfr_lngamma (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  649. __MPFR_DECLSPEC int mpfr_lgamma (mpfr_ptr, int *, mpfr_srcptr, mpfr_rnd_t);
  650. __MPFR_DECLSPEC int mpfr_digamma (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  651. __MPFR_DECLSPEC int mpfr_zeta (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  652. __MPFR_DECLSPEC int mpfr_zeta_ui (mpfr_ptr, unsigned long, mpfr_rnd_t);
  653. __MPFR_DECLSPEC int mpfr_fac_ui (mpfr_ptr, unsigned long, mpfr_rnd_t);
  654. __MPFR_DECLSPEC int mpfr_j0 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  655. __MPFR_DECLSPEC int mpfr_j1 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  656. __MPFR_DECLSPEC int mpfr_jn (mpfr_ptr, long, mpfr_srcptr, mpfr_rnd_t);
  657. __MPFR_DECLSPEC int mpfr_y0 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  658. __MPFR_DECLSPEC int mpfr_y1 (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  659. __MPFR_DECLSPEC int mpfr_yn (mpfr_ptr, long, mpfr_srcptr, mpfr_rnd_t);
  660. __MPFR_DECLSPEC int mpfr_ai (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t);
  661. __MPFR_DECLSPEC int mpfr_min (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  662. __MPFR_DECLSPEC int mpfr_max (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  663. __MPFR_DECLSPEC int mpfr_dim (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t);
  664. __MPFR_DECLSPEC int mpfr_mul_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);
  665. __MPFR_DECLSPEC int mpfr_div_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);
  666. __MPFR_DECLSPEC int mpfr_add_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);
  667. __MPFR_DECLSPEC int mpfr_sub_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);
  668. __MPFR_DECLSPEC int mpfr_z_sub (mpfr_ptr, mpz_srcptr, mpfr_srcptr, mpfr_rnd_t);
  669. __MPFR_DECLSPEC int mpfr_cmp_z (mpfr_srcptr, mpz_srcptr);
  670. __MPFR_DECLSPEC int mpfr_fma (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
  671. mpfr_rnd_t);
  672. __MPFR_DECLSPEC int mpfr_fms (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
  673. mpfr_rnd_t);
  674. __MPFR_DECLSPEC int mpfr_fmma (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
  675. mpfr_srcptr, mpfr_rnd_t);
  676. __MPFR_DECLSPEC int mpfr_fmms (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
  677. mpfr_srcptr, mpfr_rnd_t);
  678. __MPFR_DECLSPEC int mpfr_sum (mpfr_ptr, const mpfr_ptr *, unsigned long,
  679. mpfr_rnd_t);
  680. __MPFR_DECLSPEC int mpfr_dot (mpfr_ptr, const mpfr_ptr *, const mpfr_ptr *,
  681. unsigned long, mpfr_rnd_t);
  682. __MPFR_DECLSPEC void mpfr_free_cache (void);
  683. __MPFR_DECLSPEC void mpfr_free_cache2 (mpfr_free_cache_t);
  684. __MPFR_DECLSPEC void mpfr_free_pool (void);
  685. __MPFR_DECLSPEC int mpfr_mp_memory_cleanup (void);
  686. __MPFR_DECLSPEC int mpfr_subnormalize (mpfr_ptr, int, mpfr_rnd_t);
  687. __MPFR_DECLSPEC int mpfr_strtofr (mpfr_ptr, const char *, char **, int,
  688. mpfr_rnd_t);
  689. __MPFR_DECLSPEC void mpfr_round_nearest_away_begin (mpfr_ptr);
  690. __MPFR_DECLSPEC int mpfr_round_nearest_away_end (mpfr_ptr, int);
  691. __MPFR_DECLSPEC size_t mpfr_custom_get_size (mpfr_prec_t);
  692. __MPFR_DECLSPEC void mpfr_custom_init (void *, mpfr_prec_t);
  693. __MPFR_DECLSPEC MPFR_RETURNS_NONNULL void *
  694. mpfr_custom_get_significand (mpfr_srcptr);
  695. __MPFR_DECLSPEC mpfr_exp_t mpfr_custom_get_exp (mpfr_srcptr);
  696. __MPFR_DECLSPEC void mpfr_custom_move (mpfr_ptr, void *);
  697. __MPFR_DECLSPEC void mpfr_custom_init_set (mpfr_ptr, int, mpfr_exp_t,
  698. mpfr_prec_t, void *);
  699. __MPFR_DECLSPEC int mpfr_custom_get_kind (mpfr_srcptr);
  700. __MPFR_DECLSPEC int mpfr_total_order_p (mpfr_srcptr, mpfr_srcptr);
  701. #if defined (__cplusplus)
  702. }
  703. #endif
  704. /* Define MPFR_USE_EXTENSION to avoid "gcc -pedantic" warnings. */
  705. #ifndef MPFR_EXTENSION
  706. # if defined(MPFR_USE_EXTENSION)
  707. # define MPFR_EXTENSION __extension__
  708. # else
  709. # define MPFR_EXTENSION
  710. # endif
  711. #endif
  712. /* Warning! This macro doesn't work with K&R C (e.g., compare the "gcc -E"
  713. output with and without -traditional) and shouldn't be used internally.
  714. For public use only, but see the MPFR manual. */
  715. #define MPFR_DECL_INIT(_x, _p) \
  716. MPFR_EXTENSION mp_limb_t __gmpfr_local_tab_##_x[((_p)-1)/GMP_NUMB_BITS+1]; \
  717. MPFR_EXTENSION mpfr_t _x = {{(_p),1,__MPFR_EXP_NAN,__gmpfr_local_tab_##_x}}
  718. #if MPFR_USE_C99_FEATURE
  719. /* C99 & C11 version: functions with multiple inputs supported */
  720. #define mpfr_round_nearest_away(func, rop, ...) \
  721. (mpfr_round_nearest_away_begin(rop), \
  722. mpfr_round_nearest_away_end((rop), func((rop), __VA_ARGS__, MPFR_RNDN)))
  723. #else
  724. /* C89 version: function with one input supported */
  725. #define mpfr_round_nearest_away(func, rop, op) \
  726. (mpfr_round_nearest_away_begin(rop), \
  727. mpfr_round_nearest_away_end((rop), func((rop), (op), MPFR_RNDN)))
  728. #endif
  729. /* Fast access macros to replace function interface.
  730. If the USER don't want to use the macro interface, let him make happy
  731. even if it produces faster and smaller code. */
  732. #ifndef MPFR_USE_NO_MACRO
  733. /* In the implementation of these macros, we need to make sure that the
  734. arguments are evaluated one time exactly and that type conversion is
  735. done as it would be with a function. Tests should be added to ensure
  736. that.
  737. Note that the macros for the custom interface are not concerned; the
  738. MPFR manual has been clarified. */
  739. /* Prevent x from being used as an lvalue.
  740. Thanks to Wojtek Lerch and Tim Rentsch for the idea. */
  741. #define MPFR_VALUE_OF(x) (0 ? (x) : (x))
  742. /* The following macro converts the argument to mpfr_srcptr, as in type
  743. conversion for function parameters. But it will detect disallowed
  744. implicit conversions, e.g. when the argument has an integer type. */
  745. #define MPFR_SRCPTR(x) ((mpfr_srcptr) (0 ? (x) : (mpfr_srcptr) (x)))
  746. #define MPFR_GET_SIGN(_x) MPFR_VALUE_OF(MPFR_SIGN(MPFR_SRCPTR(_x)))
  747. #define mpfr_nan_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_NAN)
  748. #define mpfr_inf_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_INF)
  749. #define mpfr_zero_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_ZERO)
  750. #define mpfr_regular_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp > __MPFR_EXP_INF)
  751. /* mpfr_sgn is documented as a macro, thus the following code is fine.
  752. But it would be safer to regard it as a function in some future
  753. MPFR version. */
  754. #define mpfr_sgn(_x) \
  755. ((_x)->_mpfr_exp < __MPFR_EXP_INF ? \
  756. (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
  757. MPFR_SIGN (_x))
  758. #define mpfr_get_prec(_x) MPFR_VALUE_OF(MPFR_SRCPTR(_x)->_mpfr_prec)
  759. #define mpfr_get_exp(_x) MPFR_VALUE_OF(MPFR_SRCPTR(_x)->_mpfr_exp)
  760. /* Note: Defining mpfr_get_exp() as a macro has the effect to disable
  761. the check that the argument is a pure FP number (done in the function);
  762. this increases the risk of undetected error and makes debugging more
  763. complex. Is it really worth in practice? (Potential FIXME) */
  764. #define mpfr_round(a,b) mpfr_rint((a), (b), MPFR_RNDNA)
  765. #define mpfr_trunc(a,b) mpfr_rint((a), (b), MPFR_RNDZ)
  766. #define mpfr_ceil(a,b) mpfr_rint((a), (b), MPFR_RNDU)
  767. #define mpfr_floor(a,b) mpfr_rint((a), (b), MPFR_RNDD)
  768. #define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp((b),(i),0)
  769. #define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp((b),(i),0)
  770. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
  771. #define mpfr_set(a,b,r) \
  772. __extension__ ({ \
  773. mpfr_srcptr _p = (b); \
  774. mpfr_set4(a,_p,r,MPFR_SIGN(_p)); \
  775. })
  776. #endif
  777. #define mpfr_abs(a,b,r) mpfr_set4(a,b,r,1)
  778. #define mpfr_copysign(a,b,c,r) mpfr_set4(a,b,r,MPFR_GET_SIGN(c))
  779. #define mpfr_setsign(a,b,s,r) mpfr_set4(a,b,r,(s) ? -1 : 1)
  780. #define mpfr_signbit(x) (MPFR_GET_SIGN(x) < 0)
  781. #define mpfr_cmp(b, c) mpfr_cmp3(b, c, 1)
  782. #define mpfr_mul_2exp(y,x,n,r) mpfr_mul_2ui((y),(x),(n),(r))
  783. #define mpfr_div_2exp(y,x,n,r) mpfr_div_2ui((y),(x),(n),(r))
  784. /* When using GCC or ICC, optimize certain common comparisons and affectations.
  785. Added casts to improve robustness in case of undefined behavior and
  786. compiler extensions based on UB (in particular -fwrapv). MPFR doesn't
  787. use such extensions, but these macros will be used by 3rd-party code,
  788. where such extensions may be required.
  789. Moreover casts to unsigned long have been added to avoid warnings in
  790. programs that use MPFR and are compiled with -Wconversion; such casts
  791. are OK since if X is a constant expression, then (unsigned long) X is
  792. also a constant expression, so that the optimizations still work. The
  793. warnings are probably related to the following two bugs:
  794. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210
  795. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470 (possibly a variant)
  796. and the casts could be removed once these bugs are fixed.
  797. Casts shouldn't be used on the generic calls (to the ..._2exp functions),
  798. where implicit conversions are performed. Indeed, having at least one
  799. implicit conversion in the macro allows the compiler to emit diagnostics
  800. when normally expected, for instance in the following call:
  801. mpfr_set_ui (x, "foo", MPFR_RNDN);
  802. If this is not possible (for future macros), one of the tricks described
  803. on http://groups.google.com/group/comp.std.c/msg/e92abd24bf9eaf7b could
  804. be used. */
  805. #if defined (__GNUC__) && !defined(__cplusplus)
  806. #if (__GNUC__ >= 2)
  807. #undef mpfr_cmp_ui
  808. /* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0.
  809. But warning! mpfr_sgn is specified as a macro in the API, thus the macro
  810. mustn't be used if side effects are possible, like here. */
  811. #define mpfr_cmp_ui(_f,_u) \
  812. (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
  813. (mpfr_sgn) (_f) : \
  814. mpfr_cmp_ui_2exp ((_f), (_u), 0))
  815. #undef mpfr_cmp_si
  816. #define mpfr_cmp_si(_f,_s) \
  817. (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
  818. mpfr_cmp_ui ((_f), (mpfr_ulong) (mpfr_long) (_s)) : \
  819. mpfr_cmp_si_2exp ((_f), (_s), 0))
  820. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
  821. #undef mpfr_set_ui
  822. #define mpfr_set_ui(_f,_u,_r) \
  823. (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
  824. __extension__ ({ \
  825. mpfr_ptr _p = (_f); \
  826. _p->_mpfr_sign = 1; \
  827. _p->_mpfr_exp = __MPFR_EXP_ZERO; \
  828. (mpfr_void) (_r); 0; }) : \
  829. mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
  830. #endif
  831. #undef mpfr_set_si
  832. #define mpfr_set_si(_f,_s,_r) \
  833. (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
  834. mpfr_set_ui ((_f), (mpfr_ulong) (mpfr_long) (_s), (_r)) : \
  835. mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
  836. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  837. /* If the source is a constant number that is a power of 2,
  838. optimize the call */
  839. #undef mpfr_mul_ui
  840. #define mpfr_mul_ui(_f, _g, _u,_r) \
  841. (__builtin_constant_p (_u) && (mpfr_ulong) (_u) >= 1 && \
  842. ((mpfr_ulong) (_u) & ((mpfr_ulong) (_u) - 1)) == 0 ? \
  843. mpfr_mul_2si((_f), (_g), __builtin_ctzl (_u), (_r)) : \
  844. mpfr_mul_ui ((_f), (_g), (_u), (_r)))
  845. #undef mpfr_div_ui
  846. #define mpfr_div_ui(_f, _g, _u,_r) \
  847. (__builtin_constant_p (_u) && (mpfr_ulong) (_u) >= 1 && \
  848. ((mpfr_ulong) (_u) & ((mpfr_ulong) (_u) - 1)) == 0 ? \
  849. mpfr_mul_2si((_f), (_g), - __builtin_ctzl (_u), (_r)) : \
  850. mpfr_div_ui ((_f), (_g), (_u), (_r)))
  851. #endif
  852. /* If the source is a constant number that is non-negative,
  853. optimize the call */
  854. #undef mpfr_mul_si
  855. #define mpfr_mul_si(_f, _g, _s,_r) \
  856. (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
  857. mpfr_mul_ui ((_f), (_g), (mpfr_ulong) (mpfr_long) (_s), (_r)) : \
  858. mpfr_mul_si ((_f), (_g), (_s), (_r)))
  859. #undef mpfr_div_si
  860. #define mpfr_div_si(_f, _g, _s,_r) \
  861. (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
  862. mpfr_div_ui ((_f), (_g), (mpfr_ulong) (mpfr_long) (_s), (_r)) : \
  863. mpfr_div_si ((_f), (_g), (_s), (_r)))
  864. #endif
  865. #endif
  866. /* Macro version of mpfr_stack interface for fast access */
  867. #define mpfr_custom_get_size(p) ((mpfr_size_t) \
  868. (((p)+GMP_NUMB_BITS-1)/GMP_NUMB_BITS*sizeof (mp_limb_t)))
  869. #define mpfr_custom_init(m,p) do {} while (0)
  870. #define mpfr_custom_get_significand(x) ((mpfr_void*)((x)->_mpfr_d))
  871. #define mpfr_custom_get_exp(x) ((x)->_mpfr_exp)
  872. #define mpfr_custom_move(x,m) do { ((x)->_mpfr_d = (mp_limb_t*)(m)); } while (0)
  873. #define mpfr_custom_init_set(x,k,e,p,m) do { \
  874. mpfr_ptr _x = (x); \
  875. mpfr_exp_t _e; \
  876. mpfr_kind_t _t; \
  877. mpfr_int _s, _k; \
  878. _k = (k); \
  879. if (_k >= 0) { \
  880. _t = (mpfr_kind_t) _k; \
  881. _s = 1; \
  882. } else { \
  883. _t = (mpfr_kind_t) - _k; \
  884. _s = -1; \
  885. } \
  886. _e = _t == MPFR_REGULAR_KIND ? (e) : \
  887. _t == MPFR_NAN_KIND ? __MPFR_EXP_NAN : \
  888. _t == MPFR_INF_KIND ? __MPFR_EXP_INF : __MPFR_EXP_ZERO; \
  889. _x->_mpfr_prec = (p); \
  890. _x->_mpfr_sign = _s; \
  891. _x->_mpfr_exp = _e; \
  892. _x->_mpfr_d = (mp_limb_t*) (m); \
  893. } while (0)
  894. #define mpfr_custom_get_kind(x) \
  895. ( (x)->_mpfr_exp > __MPFR_EXP_INF ? \
  896. (mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (x) \
  897. : (x)->_mpfr_exp == __MPFR_EXP_INF ? \
  898. (mpfr_int) MPFR_INF_KIND * MPFR_SIGN (x) \
  899. : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (mpfr_int) MPFR_NAN_KIND \
  900. : (mpfr_int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
  901. #endif /* MPFR_USE_NO_MACRO */
  902. /* These are defined to be macros */
  903. #define mpfr_init_set_si(x, i, rnd) \
  904. ( mpfr_init(x), mpfr_set_si((x), (i), (rnd)) )
  905. #define mpfr_init_set_ui(x, i, rnd) \
  906. ( mpfr_init(x), mpfr_set_ui((x), (i), (rnd)) )
  907. #define mpfr_init_set_d(x, d, rnd) \
  908. ( mpfr_init(x), mpfr_set_d((x), (d), (rnd)) )
  909. #define mpfr_init_set_ld(x, d, rnd) \
  910. ( mpfr_init(x), mpfr_set_ld((x), (d), (rnd)) )
  911. #define mpfr_init_set_z(x, i, rnd) \
  912. ( mpfr_init(x), mpfr_set_z((x), (i), (rnd)) )
  913. #ifndef MPFR_USE_MINI_GMP
  914. #define mpfr_init_set_q(x, i, rnd) \
  915. ( mpfr_init(x), mpfr_set_q((x), (i), (rnd)) )
  916. #define mpfr_init_set_f(x, y, rnd) \
  917. ( mpfr_init(x), mpfr_set_f((x), (y), (rnd)) )
  918. #endif
  919. #define mpfr_init_set(x, y, rnd) \
  920. ( mpfr_init(x), mpfr_set((x), (y), (rnd)) )
  921. /* Compatibility layer -- obsolete functions and macros */
  922. /* Note: it is not possible to output warnings, unless one defines
  923. * a deprecated variable and uses it, e.g.
  924. * MPFR_DEPRECATED extern int mpfr_deprecated_feature;
  925. * #define MPFR_EMIN_MIN ((void)mpfr_deprecated_feature,mpfr_get_emin_min())
  926. * (the cast to void avoids a warning because the left-hand operand
  927. * has no effect).
  928. */
  929. #define mpfr_cmp_abs mpfr_cmpabs
  930. #define mpfr_round_prec(x,r,p) mpfr_prec_round(x,p,r)
  931. #define __gmp_default_rounding_mode (mpfr_get_default_rounding_mode())
  932. #define __mpfr_emin (mpfr_get_emin())
  933. #define __mpfr_emax (mpfr_get_emax())
  934. #define __mpfr_default_fp_bit_precision (mpfr_get_default_fp_bit_precision())
  935. #define MPFR_EMIN_MIN mpfr_get_emin_min()
  936. #define MPFR_EMIN_MAX mpfr_get_emin_max()
  937. #define MPFR_EMAX_MIN mpfr_get_emax_min()
  938. #define MPFR_EMAX_MAX mpfr_get_emax_max()
  939. #define mpfr_version (mpfr_get_version())
  940. #ifndef mpz_set_fr
  941. # define mpz_set_fr mpfr_get_z
  942. #endif
  943. #define mpfr_get_z_exp mpfr_get_z_2exp
  944. #define mpfr_custom_get_mantissa mpfr_custom_get_significand
  945. #endif /* __MPFR_H */
  946. /* Check if <stdint.h> / <inttypes.h> is included or if the user
  947. explicitly wants intmax_t. Automatic detection is done by
  948. checking:
  949. - INTMAX_C and UINTMAX_C, but not if the compiler is a C++ one
  950. (as suggested by Patrick Pelissier) because the test does not
  951. work well in this case. See:
  952. https://sympa.inria.fr/sympa/arc/mpfr/2010-02/msg00025.html
  953. We do not check INTMAX_MAX and UINTMAX_MAX because under Solaris,
  954. these macros are always defined by <limits.h> (i.e. even when
  955. <stdint.h> and <inttypes.h> are not included).
  956. - _STDINT_H (defined by the glibc), _STDINT_H_ (defined under
  957. Mac OS X) and _STDINT (defined under MS Visual Studio), but
  958. this test may not work with all implementations.
  959. Portable software should not rely on these tests.
  960. */
  961. #if (defined (INTMAX_C) && defined (UINTMAX_C) && !defined(__cplusplus)) || \
  962. defined (MPFR_USE_INTMAX_T) || \
  963. defined (_STDINT_H) || defined (_STDINT_H_) || defined (_STDINT) || \
  964. defined (_SYS_STDINT_H_) /* needed for FreeBSD */
  965. # ifndef _MPFR_H_HAVE_INTMAX_T
  966. # define _MPFR_H_HAVE_INTMAX_T 1
  967. #if defined (__cplusplus)
  968. extern "C" {
  969. #endif
  970. #define mpfr_set_sj __gmpfr_set_sj
  971. #define mpfr_set_sj_2exp __gmpfr_set_sj_2exp
  972. #define mpfr_set_uj __gmpfr_set_uj
  973. #define mpfr_set_uj_2exp __gmpfr_set_uj_2exp
  974. #define mpfr_get_sj __gmpfr_mpfr_get_sj
  975. #define mpfr_get_uj __gmpfr_mpfr_get_uj
  976. __MPFR_DECLSPEC int mpfr_set_sj (mpfr_ptr, intmax_t, mpfr_rnd_t);
  977. __MPFR_DECLSPEC int mpfr_set_sj_2exp (mpfr_ptr, intmax_t, intmax_t,
  978. mpfr_rnd_t);
  979. __MPFR_DECLSPEC int mpfr_set_uj (mpfr_ptr, uintmax_t, mpfr_rnd_t);
  980. __MPFR_DECLSPEC int mpfr_set_uj_2exp (mpfr_ptr, uintmax_t, intmax_t,
  981. mpfr_rnd_t);
  982. __MPFR_DECLSPEC intmax_t mpfr_get_sj (mpfr_srcptr, mpfr_rnd_t);
  983. __MPFR_DECLSPEC uintmax_t mpfr_get_uj (mpfr_srcptr, mpfr_rnd_t);
  984. #if defined (__cplusplus)
  985. }
  986. #endif
  987. # endif /* _MPFR_H_HAVE_INTMAX_T */
  988. #endif
  989. /* Check if <stdio.h> has been included or if the user wants FILE */
  990. #if defined (_GMP_H_HAVE_FILE) || defined (MPFR_USE_FILE)
  991. # ifndef _MPFR_H_HAVE_FILE
  992. # define _MPFR_H_HAVE_FILE 1
  993. #if defined (__cplusplus)
  994. extern "C" {
  995. #endif
  996. #define mpfr_inp_str __gmpfr_inp_str
  997. #define mpfr_out_str __gmpfr_out_str
  998. __MPFR_DECLSPEC size_t mpfr_inp_str (mpfr_ptr, FILE*, int, mpfr_rnd_t);
  999. __MPFR_DECLSPEC size_t mpfr_out_str (FILE*, int, size_t, mpfr_srcptr,
  1000. mpfr_rnd_t);
  1001. #ifndef MPFR_USE_MINI_GMP
  1002. #define mpfr_fprintf __gmpfr_fprintf
  1003. __MPFR_DECLSPEC int mpfr_fprintf (FILE*, const char*, ...);
  1004. #endif
  1005. #define mpfr_fpif_export __gmpfr_fpif_export
  1006. #define mpfr_fpif_import __gmpfr_fpif_import
  1007. __MPFR_DECLSPEC int mpfr_fpif_export (FILE*, mpfr_ptr);
  1008. __MPFR_DECLSPEC int mpfr_fpif_import (mpfr_ptr, FILE*);
  1009. #if defined (__cplusplus)
  1010. }
  1011. #endif
  1012. # endif /* _MPFR_H_HAVE_FILE */
  1013. #endif
  1014. /* check if <stdarg.h> has been included or if the user wants va_list */
  1015. #if defined (_GMP_H_HAVE_VA_LIST) || defined (MPFR_USE_VA_LIST)
  1016. # ifndef _MPFR_H_HAVE_VA_LIST
  1017. # define _MPFR_H_HAVE_VA_LIST 1
  1018. #if defined (__cplusplus)
  1019. extern "C" {
  1020. #endif
  1021. #define mpfr_vprintf __gmpfr_vprintf
  1022. #define mpfr_vasprintf __gmpfr_vasprintf
  1023. #define mpfr_vsprintf __gmpfr_vsprintf
  1024. #define mpfr_vsnprintf __gmpfr_vsnprintf
  1025. __MPFR_DECLSPEC int mpfr_vprintf (const char*, va_list);
  1026. __MPFR_DECLSPEC int mpfr_vasprintf (char**, const char*, va_list);
  1027. __MPFR_DECLSPEC int mpfr_vsprintf (char*, const char*, va_list);
  1028. __MPFR_DECLSPEC int mpfr_vsnprintf (char*, size_t, const char*, va_list);
  1029. #if defined (__cplusplus)
  1030. }
  1031. #endif
  1032. # endif /* _MPFR_H_HAVE_VA_LIST */
  1033. #endif
  1034. /* check if <stdarg.h> has been included and if FILE is available
  1035. (see above) */
  1036. #if defined (_MPFR_H_HAVE_VA_LIST) && defined (_MPFR_H_HAVE_FILE)
  1037. # ifndef _MPFR_H_HAVE_VA_LIST_FILE
  1038. # define _MPFR_H_HAVE_VA_LIST_FILE 1
  1039. #if defined (__cplusplus)
  1040. extern "C" {
  1041. #endif
  1042. #define mpfr_vfprintf __gmpfr_vfprintf
  1043. __MPFR_DECLSPEC int mpfr_vfprintf (FILE*, const char*, va_list);
  1044. #if defined (__cplusplus)
  1045. }
  1046. #endif
  1047. # endif /* _MPFR_H_HAVE_VA_LIST_FILE */
  1048. #endif