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