1/* mpfr.h -- Include file for mpfr.
2
3Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4Contributed by the Arenaire and Cacao 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
20http://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 3
28#define MPFR_VERSION_MINOR 0
29#define MPFR_VERSION_PATCHLEVEL 1
30#define MPFR_VERSION_STRING "3.0.1-p4"
31
32/* Macros dealing with MPFR VERSION */
33#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
34#define MPFR_VERSION \
35MPFR_VERSION_NUM(MPFR_VERSION_MAJOR,MPFR_VERSION_MINOR,MPFR_VERSION_PATCHLEVEL)
36
37/* Check if GMP is included, and try to include it (Works with local GMP) */
38#ifndef __GMP_H__
39# include <gmp.h>
40#endif
41
42/* Check if stdio.h is included or if the user wants FILE */
43#if defined (_GMP_H_HAVE_FILE) || defined (MPFR_USE_FILE)
44# define _MPFR_H_HAVE_FILE 1
45#endif
46
47#if defined (_GMP_H_HAVE_VA_LIST)
48# define _MPFR_H_HAVE_VA_LIST 1
49#endif
50
51/* Check if <stdint.h> / <inttypes.h> is included or if the user
52   explicitly wants intmax_t. Automatical detection is done by
53   checking:
54     - INTMAX_C and UINTMAX_C, but not if the compiler is a C++ one
55       (as suggested by Patrick Pelissier) because the test does not
56       work well in this case. See:
57         http://websympa.loria.fr/wwsympa/arc/mpfr/2010-02/msg00025.html
58       We do not check INTMAX_MAX and UINTMAX_MAX because under Solaris,
59       these macros are always defined by <limits.h> (i.e. even when
60       <stdint.h> and <inttypes.h> are not included).
61     - _STDINT_H (defined by the glibc) and _STDINT_H_ (defined under
62       Mac OS X), but this test may not work with all implementations.
63       Portable software should not rely on these tests.
64*/
65#if (defined (INTMAX_C) && defined (UINTMAX_C) && !defined(__cplusplus)) || \
66  defined (MPFR_USE_INTMAX_T) || defined (_STDINT_H) || defined (_STDINT_H_)
67# define _MPFR_H_HAVE_INTMAX_T 1
68#endif
69
70/* Avoid some problems with macro expansion if the user defines macros
71   with the same name as keywords. By convention, identifiers and macro
72   names starting with mpfr_ are reserved by MPFR. */
73typedef void            mpfr_void;
74typedef int             mpfr_int;
75typedef unsigned int    mpfr_uint;
76typedef long            mpfr_long;
77typedef unsigned long   mpfr_ulong;
78typedef size_t          mpfr_size_t;
79
80/* Definition of rounding modes (DON'T USE MPFR_RNDNA!).
81   Warning! Changing the contents of this enum should be seen as an
82   interface change since the old and the new types are not compatible
83   (the integer type compatible with the enumerated type can even change,
84   see ISO C99, 6.7.2.2#4), and in Makefile.am, AGE should be set to 0.
85
86   MPFR_RNDU must appear just before MPFR_RNDD (see
87   MPFR_IS_RNDUTEST_OR_RNDDNOTTEST in mpfr-impl.h).
88
89   MPFR_RNDF has been added, though not implemented yet, in order to avoid
90   to break the ABI once faithful rounding gets implemented.
91
92   If you change the order of the rounding modes, please update the routines
93   in texceptions.c which assume 0=RNDN, 1=RNDZ, 2=RNDU, 3=RNDD, 4=RNDA.
94*/
95typedef enum {
96  MPFR_RNDN=0,  /* round to nearest, with ties to even */
97  MPFR_RNDZ,    /* round toward zero */
98  MPFR_RNDU,    /* round toward +Inf */
99  MPFR_RNDD,    /* round toward -Inf */
100  MPFR_RNDA,    /* round away from zero */
101  MPFR_RNDF,    /* faithful rounding (not implemented yet) */
102  MPFR_RNDNA=-1 /* round to nearest, with ties away from zero (mpfr_round) */
103} mpfr_rnd_t;
104
105/* kept for compatibility with MPFR 2.4.x and before */
106#define GMP_RNDN MPFR_RNDN
107#define GMP_RNDZ MPFR_RNDZ
108#define GMP_RNDU MPFR_RNDU
109#define GMP_RNDD MPFR_RNDD
110
111/* Define precision : 1 (short), 2 (int) or 3 (long) (DON'T USE IT!)*/
112#ifndef _MPFR_PREC_FORMAT
113# if __GMP_MP_SIZE_T_INT == 1
114#  define _MPFR_PREC_FORMAT 2
115# else
116#  define _MPFR_PREC_FORMAT 3
117# endif
118#endif
119
120/* Let's make mpfr_prec_t signed in order to avoid problems due to the
121   usual arithmetic conversions when mixing mpfr_prec_t and mpfr_exp_t
122   in an expression (for error analysis) if casts are forgotten. */
123#if   _MPFR_PREC_FORMAT == 1
124typedef short mpfr_prec_t;
125typedef unsigned short mpfr_uprec_t;
126#elif _MPFR_PREC_FORMAT == 2
127typedef int   mpfr_prec_t;
128typedef unsigned int   mpfr_uprec_t;
129#elif _MPFR_PREC_FORMAT == 3
130typedef long  mpfr_prec_t;
131typedef unsigned long  mpfr_uprec_t;
132#else
133# error "Invalid MPFR Prec format"
134#endif
135
136/* Definition of precision limits without needing <limits.h> */
137/* Note: the casts allows the expression to yield the wanted behavior
138   for _MPFR_PREC_FORMAT == 1 (due to integer promotion rules). */
139#define MPFR_PREC_MIN 2
140#define MPFR_PREC_MAX ((mpfr_prec_t)((mpfr_uprec_t)(~(mpfr_uprec_t)0)>>1))
141
142/* Definition of sign */
143typedef int          mpfr_sign_t;
144
145/* Definition of the exponent: same as in GMP. */
146typedef mp_exp_t     mpfr_exp_t;
147
148/* Definition of the standard exponent limits */
149#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((mpfr_ulong) 1 << 30) - 1))
150#define MPFR_EMIN_DEFAULT (-(MPFR_EMAX_DEFAULT))
151
152/* Definition of the main structure */
153typedef struct {
154  mpfr_prec_t  _mpfr_prec;
155  mpfr_sign_t  _mpfr_sign;
156  mpfr_exp_t   _mpfr_exp;
157  mp_limb_t   *_mpfr_d;
158} __mpfr_struct;
159
160/* Compatibility with previous types of MPFR */
161#ifndef mp_rnd_t
162# define mp_rnd_t  mpfr_rnd_t
163#endif
164#ifndef mp_prec_t
165# define mp_prec_t mpfr_prec_t
166#endif
167
168/*
169   The represented number is
170      _sign*(_d[k-1]/B+_d[k-2]/B^2+...+_d[0]/B^k)*2^_exp
171   where k=ceil(_mp_prec/GMP_NUMB_BITS) and B=2^GMP_NUMB_BITS.
172
173   For the msb (most significant bit) normalized representation, we must have
174      _d[k-1]>=B/2, unless the number is singular.
175
176   We must also have the last k*GMP_NUMB_BITS-_prec bits set to zero.
177*/
178
179typedef __mpfr_struct mpfr_t[1];
180typedef __mpfr_struct *mpfr_ptr;
181typedef __gmp_const __mpfr_struct *mpfr_srcptr;
182
183/* For those who need a direct and fast access to the sign field.
184   However it is not in the API, thus use it at your own risk: it might
185   not be supported, or change name, in further versions!
186   Unfortunately, it must be defined here (instead of MPFR's internal
187   header file mpfr-impl.h) because it is used by some macros below.
188*/
189#define MPFR_SIGN(x) ((x)->_mpfr_sign)
190
191/* Stack interface */
192typedef enum {
193  MPFR_NAN_KIND = 0,
194  MPFR_INF_KIND = 1, MPFR_ZERO_KIND = 2, MPFR_REGULAR_KIND = 3
195} mpfr_kind_t;
196
197/* GMP defines:
198    + size_t:                Standard size_t
199    + __GMP_ATTRIBUTE_PURE   Attribute for math functions.
200    + __GMP_NOTHROW          For C++: can't throw .
201    + __GMP_EXTERN_INLINE    Attribute for inline function.
202    * __gmp_const            const (Supports for K&R compiler only for mpfr.h).
203    + __GMP_DECLSPEC_EXPORT  compiling to go into a DLL
204    + __GMP_DECLSPEC_IMPORT  compiling to go into a application
205*/
206/* Extra MPFR defines */
207#define __MPFR_SENTINEL_ATTR
208#if defined (__GNUC__)
209# if __GNUC__ >= 4
210#  undef __MPFR_SENTINEL_ATTR
211#  define __MPFR_SENTINEL_ATTR __attribute__ ((sentinel))
212# endif
213#endif
214
215/* Prototypes: Support of K&R compiler */
216#if defined (__GMP_PROTO)
217# define _MPFR_PROTO __GMP_PROTO
218#elif defined (__STDC__) || defined (__cplusplus)
219# define _MPFR_PROTO(x) x
220#else
221# define _MPFR_PROTO(x) ()
222#endif
223/* Support for WINDOWS Dll:
224   Check if we are inside a MPFR build, and if so export the functions.
225   Otherwise does the same thing as GMP */
226#if defined(__MPFR_WITHIN_MPFR) && __GMP_LIBGMP_DLL
227# define __MPFR_DECLSPEC __GMP_DECLSPEC_EXPORT
228#else
229# define __MPFR_DECLSPEC __GMP_DECLSPEC
230#endif
231
232/* Note: In order to be declared, some functions need a specific
233   system header to be included *before* "mpfr.h". If the user
234   forgets to include the header, the MPFR function prototype in
235   the user object file is not correct. To avoid wrong results,
236   we raise a linker error in that case by changing their internal
237   name in the library (prefixed by __gmpfr instead of mpfr). See
238   the lines of the form "#define mpfr_xxx __gmpfr_xxx" below. */
239
240#if defined (__cplusplus)
241extern "C" {
242#endif
243
244__MPFR_DECLSPEC __gmp_const char * mpfr_get_version _MPFR_PROTO ((void));
245__MPFR_DECLSPEC __gmp_const char * mpfr_get_patches _MPFR_PROTO ((void));
246__MPFR_DECLSPEC int mpfr_buildopt_tls_p     _MPFR_PROTO ((void));
247__MPFR_DECLSPEC int mpfr_buildopt_decimal_p _MPFR_PROTO ((void));
248
249__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin     _MPFR_PROTO ((void));
250__MPFR_DECLSPEC int        mpfr_set_emin     _MPFR_PROTO ((mpfr_exp_t));
251__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_min _MPFR_PROTO ((void));
252__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_max _MPFR_PROTO ((void));
253__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax     _MPFR_PROTO ((void));
254__MPFR_DECLSPEC int        mpfr_set_emax     _MPFR_PROTO ((mpfr_exp_t));
255__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_min _MPFR_PROTO ((void));
256__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_max _MPFR_PROTO ((void));
257
258__MPFR_DECLSPEC void mpfr_set_default_rounding_mode _MPFR_PROTO((mpfr_rnd_t));
259__MPFR_DECLSPEC mpfr_rnd_t mpfr_get_default_rounding_mode _MPFR_PROTO((void));
260__MPFR_DECLSPEC __gmp_const char *
261   mpfr_print_rnd_mode _MPFR_PROTO((mpfr_rnd_t));
262
263__MPFR_DECLSPEC void mpfr_clear_flags _MPFR_PROTO ((void));
264__MPFR_DECLSPEC void mpfr_clear_underflow _MPFR_PROTO ((void));
265__MPFR_DECLSPEC void mpfr_clear_overflow _MPFR_PROTO ((void));
266__MPFR_DECLSPEC void mpfr_clear_nanflag _MPFR_PROTO ((void));
267__MPFR_DECLSPEC void mpfr_clear_inexflag _MPFR_PROTO ((void));
268__MPFR_DECLSPEC void mpfr_clear_erangeflag _MPFR_PROTO ((void));
269
270__MPFR_DECLSPEC void mpfr_set_underflow _MPFR_PROTO ((void));
271__MPFR_DECLSPEC void mpfr_set_overflow _MPFR_PROTO ((void));
272__MPFR_DECLSPEC void mpfr_set_nanflag _MPFR_PROTO ((void));
273__MPFR_DECLSPEC void mpfr_set_inexflag _MPFR_PROTO ((void));
274__MPFR_DECLSPEC void mpfr_set_erangeflag _MPFR_PROTO ((void));
275
276__MPFR_DECLSPEC int mpfr_underflow_p _MPFR_PROTO ((void));
277__MPFR_DECLSPEC int mpfr_overflow_p _MPFR_PROTO ((void));
278__MPFR_DECLSPEC int mpfr_nanflag_p _MPFR_PROTO ((void));
279__MPFR_DECLSPEC int mpfr_inexflag_p _MPFR_PROTO ((void));
280__MPFR_DECLSPEC int mpfr_erangeflag_p _MPFR_PROTO ((void));
281
282__MPFR_DECLSPEC int
283  mpfr_check_range _MPFR_PROTO ((mpfr_ptr, int, mpfr_rnd_t));
284
285__MPFR_DECLSPEC void mpfr_init2 _MPFR_PROTO ((mpfr_ptr, mpfr_prec_t));
286__MPFR_DECLSPEC void mpfr_init _MPFR_PROTO ((mpfr_ptr));
287__MPFR_DECLSPEC void mpfr_clear _MPFR_PROTO ((mpfr_ptr));
288
289__MPFR_DECLSPEC void
290  mpfr_inits2 _MPFR_PROTO ((mpfr_prec_t, mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
291__MPFR_DECLSPEC void
292  mpfr_inits _MPFR_PROTO ((mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
293__MPFR_DECLSPEC void
294  mpfr_clears _MPFR_PROTO ((mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
295
296__MPFR_DECLSPEC int
297  mpfr_prec_round _MPFR_PROTO ((mpfr_ptr, mpfr_prec_t, mpfr_rnd_t));
298__MPFR_DECLSPEC int
299  mpfr_can_round _MPFR_PROTO ((mpfr_srcptr, mpfr_exp_t, mpfr_rnd_t, mpfr_rnd_t,
300                               mpfr_prec_t));
301__MPFR_DECLSPEC mpfr_prec_t mpfr_min_prec _MPFR_PROTO ((mpfr_srcptr));
302
303__MPFR_DECLSPEC mpfr_exp_t mpfr_get_exp _MPFR_PROTO ((mpfr_srcptr));
304__MPFR_DECLSPEC int mpfr_set_exp _MPFR_PROTO ((mpfr_ptr, mpfr_exp_t));
305__MPFR_DECLSPEC mpfr_prec_t mpfr_get_prec _MPFR_PROTO((mpfr_srcptr));
306__MPFR_DECLSPEC void mpfr_set_prec _MPFR_PROTO((mpfr_ptr, mpfr_prec_t));
307__MPFR_DECLSPEC void mpfr_set_prec_raw _MPFR_PROTO((mpfr_ptr, mpfr_prec_t));
308__MPFR_DECLSPEC void mpfr_set_default_prec _MPFR_PROTO((mpfr_prec_t));
309__MPFR_DECLSPEC mpfr_prec_t mpfr_get_default_prec _MPFR_PROTO((void));
310
311__MPFR_DECLSPEC int mpfr_set_d _MPFR_PROTO ((mpfr_ptr, double, mpfr_rnd_t));
312__MPFR_DECLSPEC int mpfr_set_flt _MPFR_PROTO ((mpfr_ptr, float, mpfr_rnd_t));
313#ifdef MPFR_WANT_DECIMAL_FLOATS
314__MPFR_DECLSPEC int mpfr_set_decimal64 _MPFR_PROTO ((mpfr_ptr, _Decimal64,
315                                                     mpfr_rnd_t));
316#endif
317__MPFR_DECLSPEC int
318  mpfr_set_ld _MPFR_PROTO ((mpfr_ptr, long double, mpfr_rnd_t));
319__MPFR_DECLSPEC int
320  mpfr_set_z _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, mpfr_rnd_t));
321__MPFR_DECLSPEC int
322  mpfr_set_z_2exp _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, mpfr_exp_t, mpfr_rnd_t));
323__MPFR_DECLSPEC void mpfr_set_nan _MPFR_PROTO ((mpfr_ptr));
324__MPFR_DECLSPEC void mpfr_set_inf _MPFR_PROTO ((mpfr_ptr, int));
325__MPFR_DECLSPEC void mpfr_set_zero _MPFR_PROTO ((mpfr_ptr, int));
326__MPFR_DECLSPEC int
327  mpfr_set_f _MPFR_PROTO ((mpfr_ptr, mpf_srcptr, mpfr_rnd_t));
328__MPFR_DECLSPEC int
329  mpfr_get_f _MPFR_PROTO ((mpf_ptr, mpfr_srcptr, mpfr_rnd_t));
330__MPFR_DECLSPEC int mpfr_set_si _MPFR_PROTO ((mpfr_ptr, long, mpfr_rnd_t));
331__MPFR_DECLSPEC int
332  mpfr_set_ui _MPFR_PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t));
333__MPFR_DECLSPEC int
334  mpfr_set_si_2exp _MPFR_PROTO ((mpfr_ptr, long, mpfr_exp_t, mpfr_rnd_t));
335__MPFR_DECLSPEC int
336  mpfr_set_ui_2exp _MPFR_PROTO ((mpfr_ptr,unsigned long,mpfr_exp_t,mpfr_rnd_t));
337__MPFR_DECLSPEC int
338  mpfr_set_q _MPFR_PROTO ((mpfr_ptr, mpq_srcptr, mpfr_rnd_t));
339__MPFR_DECLSPEC int
340  mpfr_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t));
341__MPFR_DECLSPEC int
342  mpfr_init_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int,
343                                  mpfr_rnd_t));
344__MPFR_DECLSPEC int
345  mpfr_set4 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int));
346__MPFR_DECLSPEC int
347  mpfr_abs _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
348__MPFR_DECLSPEC int
349  mpfr_set _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
350__MPFR_DECLSPEC int mpfr_neg _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
351__MPFR_DECLSPEC int mpfr_signbit _MPFR_PROTO ((mpfr_srcptr));
352__MPFR_DECLSPEC int
353  mpfr_setsign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, int, mpfr_rnd_t));
354__MPFR_DECLSPEC int
355  mpfr_copysign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t));
356
357#ifdef _MPFR_H_HAVE_INTMAX_T
358#define mpfr_set_sj __gmpfr_set_sj
359#define mpfr_set_sj_2exp __gmpfr_set_sj_2exp
360#define mpfr_set_uj __gmpfr_set_uj
361#define mpfr_set_uj_2exp __gmpfr_set_uj_2exp
362#define mpfr_get_sj __gmpfr_mpfr_get_sj
363#define mpfr_get_uj __gmpfr_mpfr_get_uj
364__MPFR_DECLSPEC int mpfr_set_sj _MPFR_PROTO ((mpfr_t, intmax_t, mpfr_rnd_t));
365__MPFR_DECLSPEC int
366  mpfr_set_sj_2exp _MPFR_PROTO ((mpfr_t, intmax_t, intmax_t, mpfr_rnd_t));
367__MPFR_DECLSPEC int mpfr_set_uj _MPFR_PROTO ((mpfr_t, uintmax_t, mpfr_rnd_t));
368__MPFR_DECLSPEC int
369  mpfr_set_uj_2exp _MPFR_PROTO ((mpfr_t, uintmax_t, intmax_t, mpfr_rnd_t));
370__MPFR_DECLSPEC intmax_t mpfr_get_sj _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
371__MPFR_DECLSPEC uintmax_t mpfr_get_uj _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
372#endif
373
374__MPFR_DECLSPEC mpfr_exp_t mpfr_get_z_2exp _MPFR_PROTO ((mpz_ptr, mpfr_srcptr));
375__MPFR_DECLSPEC float mpfr_get_flt _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
376__MPFR_DECLSPEC double mpfr_get_d _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
377#ifdef MPFR_WANT_DECIMAL_FLOATS
378__MPFR_DECLSPEC _Decimal64 mpfr_get_decimal64 _MPFR_PROTO ((mpfr_srcptr,
379                                                           mpfr_rnd_t));
380#endif
381__MPFR_DECLSPEC long double mpfr_get_ld _MPFR_PROTO ((mpfr_srcptr,
382                                                      mpfr_rnd_t));
383__MPFR_DECLSPEC double mpfr_get_d1 _MPFR_PROTO ((mpfr_srcptr));
384__MPFR_DECLSPEC double mpfr_get_d_2exp _MPFR_PROTO ((long*, mpfr_srcptr,
385                                                     mpfr_rnd_t));
386__MPFR_DECLSPEC long double mpfr_get_ld_2exp _MPFR_PROTO ((long*, mpfr_srcptr,
387                                                           mpfr_rnd_t));
388__MPFR_DECLSPEC long mpfr_get_si _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
389__MPFR_DECLSPEC unsigned long mpfr_get_ui _MPFR_PROTO ((mpfr_srcptr,
390                                                        mpfr_rnd_t));
391__MPFR_DECLSPEC char*mpfr_get_str _MPFR_PROTO ((char*, mpfr_exp_t*, int, size_t,
392                                                mpfr_srcptr, mpfr_rnd_t));
393__MPFR_DECLSPEC int mpfr_get_z _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f,
394                                             mpfr_rnd_t));
395
396__MPFR_DECLSPEC void mpfr_free_str _MPFR_PROTO ((char *));
397
398__MPFR_DECLSPEC int mpfr_urandom _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t,
399                                               mpfr_rnd_t));
400__MPFR_DECLSPEC int mpfr_urandomb _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t));
401
402__MPFR_DECLSPEC void mpfr_nextabove _MPFR_PROTO ((mpfr_ptr));
403__MPFR_DECLSPEC void mpfr_nextbelow _MPFR_PROTO ((mpfr_ptr));
404__MPFR_DECLSPEC void mpfr_nexttoward _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr));
405
406#ifdef _MPFR_H_HAVE_FILE
407#define mpfr_inp_str __gmpfr_inp_str
408#define mpfr_out_str __gmpfr_out_str
409__MPFR_DECLSPEC size_t mpfr_inp_str _MPFR_PROTO ((mpfr_ptr, FILE*, int,
410                                                  mpfr_rnd_t));
411__MPFR_DECLSPEC size_t mpfr_out_str _MPFR_PROTO ((FILE*, int, size_t,
412                                                  mpfr_srcptr, mpfr_rnd_t));
413#define mpfr_fprintf __gmpfr_fprintf
414__MPFR_DECLSPEC int mpfr_fprintf _MPFR_PROTO ((FILE*, __gmp_const char*,
415                                               ...));
416#endif
417__MPFR_DECLSPEC int mpfr_printf _MPFR_PROTO ((__gmp_const char*, ...));
418__MPFR_DECLSPEC int mpfr_asprintf _MPFR_PROTO ((char**, __gmp_const char*,
419                                                ...));
420__MPFR_DECLSPEC int mpfr_sprintf _MPFR_PROTO ((char*, __gmp_const char*,
421                                               ...));
422__MPFR_DECLSPEC int mpfr_snprintf _MPFR_PROTO ((char*, size_t,
423                                                __gmp_const char*, ...));
424
425#ifdef _MPFR_H_HAVE_VA_LIST
426#ifdef _MPFR_H_HAVE_FILE
427#define mpfr_vfprintf __gmpfr_vfprintf
428__MPFR_DECLSPEC int mpfr_vfprintf _MPFR_PROTO ((FILE*, __gmp_const char*,
429                                                va_list));
430#endif /* _MPFR_H_HAVE_FILE */
431#define mpfr_vprintf __gmpfr_vprintf
432#define mpfr_vasprintf __gmpfr_vasprintf
433#define mpfr_vsprintf __gmpfr_vsprintf
434#define mpfr_vsnprintf __gmpfr_vsnprintf
435__MPFR_DECLSPEC int mpfr_vprintf _MPFR_PROTO ((__gmp_const char*, va_list));
436__MPFR_DECLSPEC int mpfr_vasprintf _MPFR_PROTO ((char**, __gmp_const char*,
437                                                 va_list));
438__MPFR_DECLSPEC int mpfr_vsprintf _MPFR_PROTO ((char*, __gmp_const char*,
439                                               va_list));
440__MPFR_DECLSPEC int mpfr_vsnprintf _MPFR_PROTO ((char*, size_t,
441                                                __gmp_const char*, va_list));
442#endif /* _MPFR_H_HAVE_VA_LIST */
443
444__MPFR_DECLSPEC int mpfr_pow _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
445                                           mpfr_srcptr, mpfr_rnd_t));
446__MPFR_DECLSPEC int mpfr_pow_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
447                                              long int, mpfr_rnd_t));
448__MPFR_DECLSPEC int mpfr_pow_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
449                                              unsigned long int, mpfr_rnd_t));
450__MPFR_DECLSPEC int mpfr_ui_pow_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int,
451                                             unsigned long int, mpfr_rnd_t));
452__MPFR_DECLSPEC int mpfr_ui_pow _MPFR_PROTO ((mpfr_ptr, unsigned long int,
453                                              mpfr_srcptr, mpfr_rnd_t));
454__MPFR_DECLSPEC int mpfr_pow_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
455                                             mpz_srcptr, mpfr_rnd_t));
456
457__MPFR_DECLSPEC int mpfr_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
458                                            mpfr_rnd_t));
459__MPFR_DECLSPEC int mpfr_sqrt_ui _MPFR_PROTO ((mpfr_ptr, unsigned long,
460                                               mpfr_rnd_t));
461__MPFR_DECLSPEC int mpfr_rec_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
462                                                mpfr_rnd_t));
463
464__MPFR_DECLSPEC int mpfr_add _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
465                                           mpfr_srcptr, mpfr_rnd_t));
466__MPFR_DECLSPEC int mpfr_sub _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
467                                           mpfr_srcptr, mpfr_rnd_t));
468__MPFR_DECLSPEC int mpfr_mul _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
469                                           mpfr_srcptr, mpfr_rnd_t));
470__MPFR_DECLSPEC int mpfr_div _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
471                                           mpfr_srcptr, mpfr_rnd_t));
472
473__MPFR_DECLSPEC int mpfr_add_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
474                                              unsigned long, mpfr_rnd_t));
475__MPFR_DECLSPEC int mpfr_sub_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
476                                              unsigned long, mpfr_rnd_t));
477__MPFR_DECLSPEC int mpfr_ui_sub _MPFR_PROTO ((mpfr_ptr, unsigned long,
478                                              mpfr_srcptr, mpfr_rnd_t));
479__MPFR_DECLSPEC int mpfr_mul_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
480                                              unsigned long, mpfr_rnd_t));
481__MPFR_DECLSPEC int mpfr_div_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
482                                              unsigned long, mpfr_rnd_t));
483__MPFR_DECLSPEC int mpfr_ui_div _MPFR_PROTO ((mpfr_ptr, unsigned long,
484                                              mpfr_srcptr, mpfr_rnd_t));
485
486__MPFR_DECLSPEC int mpfr_add_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
487                                              long int, mpfr_rnd_t));
488__MPFR_DECLSPEC int mpfr_sub_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
489                                              long int, mpfr_rnd_t));
490__MPFR_DECLSPEC int mpfr_si_sub _MPFR_PROTO ((mpfr_ptr, long int,
491                                              mpfr_srcptr, mpfr_rnd_t));
492__MPFR_DECLSPEC int mpfr_mul_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
493                                              long int, mpfr_rnd_t));
494__MPFR_DECLSPEC int mpfr_div_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
495                                              long int, mpfr_rnd_t));
496__MPFR_DECLSPEC int mpfr_si_div _MPFR_PROTO ((mpfr_ptr, long int,
497                                              mpfr_srcptr, mpfr_rnd_t));
498
499__MPFR_DECLSPEC int mpfr_add_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
500                                              double, mpfr_rnd_t));
501__MPFR_DECLSPEC int mpfr_sub_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
502                                              double, mpfr_rnd_t));
503__MPFR_DECLSPEC int mpfr_d_sub _MPFR_PROTO ((mpfr_ptr, double,
504                                              mpfr_srcptr, mpfr_rnd_t));
505__MPFR_DECLSPEC int mpfr_mul_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
506                                              double, mpfr_rnd_t));
507__MPFR_DECLSPEC int mpfr_div_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
508                                              double, mpfr_rnd_t));
509__MPFR_DECLSPEC int mpfr_d_div _MPFR_PROTO ((mpfr_ptr, double,
510                                              mpfr_srcptr, mpfr_rnd_t));
511
512__MPFR_DECLSPEC int mpfr_sqr _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
513
514__MPFR_DECLSPEC int mpfr_const_pi _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
515__MPFR_DECLSPEC int mpfr_const_log2 _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
516__MPFR_DECLSPEC int mpfr_const_euler _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
517__MPFR_DECLSPEC int mpfr_const_catalan _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
518
519__MPFR_DECLSPEC int mpfr_agm _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
520                                           mpfr_rnd_t));
521
522__MPFR_DECLSPEC int mpfr_log _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
523__MPFR_DECLSPEC int mpfr_log2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
524__MPFR_DECLSPEC int mpfr_log10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
525                                             mpfr_rnd_t));
526__MPFR_DECLSPEC int mpfr_log1p _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
527                                             mpfr_rnd_t));
528
529__MPFR_DECLSPEC int mpfr_exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
530__MPFR_DECLSPEC int mpfr_exp2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
531__MPFR_DECLSPEC int mpfr_exp10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
532                                             mpfr_rnd_t));
533__MPFR_DECLSPEC int mpfr_expm1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
534                                             mpfr_rnd_t));
535__MPFR_DECLSPEC int mpfr_eint _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
536__MPFR_DECLSPEC int mpfr_li2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
537
538__MPFR_DECLSPEC int mpfr_cmp  _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
539__MPFR_DECLSPEC int mpfr_cmp3 _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr, int));
540__MPFR_DECLSPEC int mpfr_cmp_d _MPFR_PROTO ((mpfr_srcptr, double));
541__MPFR_DECLSPEC int mpfr_cmp_ld _MPFR_PROTO ((mpfr_srcptr, long double));
542__MPFR_DECLSPEC int mpfr_cmpabs _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
543__MPFR_DECLSPEC int mpfr_cmp_ui _MPFR_PROTO ((mpfr_srcptr, unsigned long));
544__MPFR_DECLSPEC int mpfr_cmp_si _MPFR_PROTO ((mpfr_srcptr, long));
545__MPFR_DECLSPEC int mpfr_cmp_ui_2exp _MPFR_PROTO ((mpfr_srcptr, unsigned long,
546                                                   mpfr_exp_t));
547__MPFR_DECLSPEC int mpfr_cmp_si_2exp _MPFR_PROTO ((mpfr_srcptr, long,
548                                                   mpfr_exp_t));
549__MPFR_DECLSPEC void mpfr_reldiff _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
550                                                mpfr_srcptr, mpfr_rnd_t));
551__MPFR_DECLSPEC int mpfr_eq _MPFR_PROTO((mpfr_srcptr, mpfr_srcptr,
552                                         unsigned long));
553__MPFR_DECLSPEC int mpfr_sgn _MPFR_PROTO ((mpfr_srcptr));
554
555__MPFR_DECLSPEC int mpfr_mul_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
556                                                unsigned long, mpfr_rnd_t));
557__MPFR_DECLSPEC int mpfr_div_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
558                                                unsigned long, mpfr_rnd_t));
559__MPFR_DECLSPEC int mpfr_mul_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
560                                               unsigned long, mpfr_rnd_t));
561__MPFR_DECLSPEC int mpfr_div_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
562                                               unsigned long, mpfr_rnd_t));
563__MPFR_DECLSPEC int mpfr_mul_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
564                                               long, mpfr_rnd_t));
565__MPFR_DECLSPEC int mpfr_div_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
566                                               long, mpfr_rnd_t));
567
568__MPFR_DECLSPEC int mpfr_rint _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
569__MPFR_DECLSPEC int mpfr_round _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
570__MPFR_DECLSPEC int mpfr_trunc _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
571__MPFR_DECLSPEC int mpfr_ceil _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
572__MPFR_DECLSPEC int mpfr_floor _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
573__MPFR_DECLSPEC int mpfr_rint_round _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
574                                                  mpfr_rnd_t));
575__MPFR_DECLSPEC int mpfr_rint_trunc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
576                                                  mpfr_rnd_t));
577__MPFR_DECLSPEC int mpfr_rint_ceil _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
578                                                 mpfr_rnd_t));
579__MPFR_DECLSPEC int mpfr_rint_floor _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
580                                                  mpfr_rnd_t));
581__MPFR_DECLSPEC int mpfr_frac _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
582__MPFR_DECLSPEC int mpfr_modf _MPFR_PROTO ((mpfr_ptr, mpfr_ptr, mpfr_srcptr,
583                                                  mpfr_rnd_t));
584__MPFR_DECLSPEC int mpfr_remquo _MPFR_PROTO ((mpfr_ptr, long*, mpfr_srcptr,
585                                              mpfr_srcptr, mpfr_rnd_t));
586__MPFR_DECLSPEC int mpfr_remainder _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
587                                                 mpfr_srcptr, mpfr_rnd_t));
588__MPFR_DECLSPEC int mpfr_fmod _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
589                                                 mpfr_srcptr, mpfr_rnd_t));
590
591__MPFR_DECLSPEC int mpfr_fits_ulong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
592__MPFR_DECLSPEC int mpfr_fits_slong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
593__MPFR_DECLSPEC int mpfr_fits_uint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
594__MPFR_DECLSPEC int mpfr_fits_sint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
595__MPFR_DECLSPEC int mpfr_fits_ushort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
596__MPFR_DECLSPEC int mpfr_fits_sshort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
597__MPFR_DECLSPEC int mpfr_fits_uintmax_p _MPFR_PROTO((mpfr_srcptr,mpfr_rnd_t));
598__MPFR_DECLSPEC int mpfr_fits_intmax_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
599
600__MPFR_DECLSPEC void mpfr_extract _MPFR_PROTO ((mpz_ptr, mpfr_srcptr,
601                                                unsigned int));
602__MPFR_DECLSPEC void mpfr_swap _MPFR_PROTO ((mpfr_ptr, mpfr_ptr));
603__MPFR_DECLSPEC void mpfr_dump _MPFR_PROTO ((mpfr_srcptr));
604
605__MPFR_DECLSPEC int mpfr_nan_p _MPFR_PROTO((mpfr_srcptr));
606__MPFR_DECLSPEC int mpfr_inf_p _MPFR_PROTO((mpfr_srcptr));
607__MPFR_DECLSPEC int mpfr_number_p _MPFR_PROTO((mpfr_srcptr));
608__MPFR_DECLSPEC int mpfr_integer_p _MPFR_PROTO ((mpfr_srcptr));
609__MPFR_DECLSPEC int mpfr_zero_p _MPFR_PROTO ((mpfr_srcptr));
610__MPFR_DECLSPEC int mpfr_regular_p _MPFR_PROTO ((mpfr_srcptr));
611
612__MPFR_DECLSPEC int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
613__MPFR_DECLSPEC int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr,
614                                                      mpfr_srcptr));
615__MPFR_DECLSPEC int mpfr_less_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
616__MPFR_DECLSPEC int mpfr_lessequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
617__MPFR_DECLSPEC int mpfr_lessgreater_p _MPFR_PROTO((mpfr_srcptr,mpfr_srcptr));
618__MPFR_DECLSPEC int mpfr_equal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
619__MPFR_DECLSPEC int mpfr_unordered_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
620
621__MPFR_DECLSPEC int mpfr_atanh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
622__MPFR_DECLSPEC int mpfr_acosh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
623__MPFR_DECLSPEC int mpfr_asinh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
624__MPFR_DECLSPEC int mpfr_cosh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
625__MPFR_DECLSPEC int mpfr_sinh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
626__MPFR_DECLSPEC int mpfr_tanh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
627__MPFR_DECLSPEC int mpfr_sinh_cosh _MPFR_PROTO ((mpfr_ptr, mpfr_ptr,
628                                               mpfr_srcptr, mpfr_rnd_t));
629
630__MPFR_DECLSPEC int mpfr_sech _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
631__MPFR_DECLSPEC int mpfr_csch _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
632__MPFR_DECLSPEC int mpfr_coth _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
633
634__MPFR_DECLSPEC int mpfr_acos _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
635__MPFR_DECLSPEC int mpfr_asin _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
636__MPFR_DECLSPEC int mpfr_atan _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
637__MPFR_DECLSPEC int mpfr_sin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
638__MPFR_DECLSPEC int mpfr_sin_cos _MPFR_PROTO ((mpfr_ptr, mpfr_ptr,
639                                               mpfr_srcptr, mpfr_rnd_t));
640__MPFR_DECLSPEC int mpfr_cos _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
641__MPFR_DECLSPEC int mpfr_tan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
642__MPFR_DECLSPEC int mpfr_atan2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_srcptr,
643                                             mpfr_rnd_t));
644__MPFR_DECLSPEC int mpfr_sec _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
645__MPFR_DECLSPEC int mpfr_csc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
646__MPFR_DECLSPEC int mpfr_cot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
647
648__MPFR_DECLSPEC int mpfr_hypot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
649                                             mpfr_srcptr, mpfr_rnd_t));
650__MPFR_DECLSPEC int mpfr_erf _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
651__MPFR_DECLSPEC int mpfr_erfc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
652__MPFR_DECLSPEC int mpfr_cbrt _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
653__MPFR_DECLSPEC int mpfr_root _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,unsigned long,mpfr_rnd_t));
654__MPFR_DECLSPEC int mpfr_gamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
655__MPFR_DECLSPEC int mpfr_lngamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
656__MPFR_DECLSPEC int mpfr_lgamma _MPFR_PROTO((mpfr_ptr,int*,mpfr_srcptr,mpfr_rnd_t));
657__MPFR_DECLSPEC int mpfr_digamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
658__MPFR_DECLSPEC int mpfr_zeta _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
659__MPFR_DECLSPEC int mpfr_zeta_ui _MPFR_PROTO ((mpfr_ptr,unsigned long,mpfr_rnd_t));
660__MPFR_DECLSPEC int mpfr_fac_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int,
661                                              mpfr_rnd_t));
662__MPFR_DECLSPEC int mpfr_j0 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
663__MPFR_DECLSPEC int mpfr_j1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
664__MPFR_DECLSPEC int mpfr_jn _MPFR_PROTO ((mpfr_ptr, long, mpfr_srcptr,
665                                          mpfr_rnd_t));
666__MPFR_DECLSPEC int mpfr_y0 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
667__MPFR_DECLSPEC int mpfr_y1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
668__MPFR_DECLSPEC int mpfr_yn _MPFR_PROTO ((mpfr_ptr, long, mpfr_srcptr,
669                                          mpfr_rnd_t));
670
671__MPFR_DECLSPEC int mpfr_ai _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
672
673__MPFR_DECLSPEC int mpfr_min _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
674                                           mpfr_rnd_t));
675__MPFR_DECLSPEC int mpfr_max _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
676                                           mpfr_rnd_t));
677__MPFR_DECLSPEC int mpfr_dim _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
678                                           mpfr_rnd_t));
679
680__MPFR_DECLSPEC int mpfr_mul_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
681                                             mpz_srcptr, mpfr_rnd_t));
682__MPFR_DECLSPEC int mpfr_div_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
683                                             mpz_srcptr, mpfr_rnd_t));
684__MPFR_DECLSPEC int mpfr_add_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
685                                             mpz_srcptr, mpfr_rnd_t));
686__MPFR_DECLSPEC int mpfr_sub_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
687                                             mpz_srcptr, mpfr_rnd_t));
688__MPFR_DECLSPEC int mpfr_cmp_z _MPFR_PROTO ((mpfr_srcptr, mpz_srcptr));
689
690__MPFR_DECLSPEC int mpfr_mul_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
691                                             mpq_srcptr, mpfr_rnd_t));
692__MPFR_DECLSPEC int mpfr_div_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
693                                             mpq_srcptr, mpfr_rnd_t));
694__MPFR_DECLSPEC int mpfr_add_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
695                                             mpq_srcptr, mpfr_rnd_t));
696__MPFR_DECLSPEC int mpfr_sub_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
697                                             mpq_srcptr, mpfr_rnd_t));
698__MPFR_DECLSPEC int mpfr_cmp_q _MPFR_PROTO ((mpfr_srcptr, mpq_srcptr));
699
700__MPFR_DECLSPEC int mpfr_cmp_f _MPFR_PROTO ((mpfr_srcptr, mpf_srcptr));
701
702__MPFR_DECLSPEC int mpfr_fma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
703                                           mpfr_srcptr, mpfr_rnd_t));
704__MPFR_DECLSPEC int mpfr_fms _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
705                                           mpfr_srcptr, mpfr_rnd_t));
706__MPFR_DECLSPEC int mpfr_sum _MPFR_PROTO ((mpfr_ptr, mpfr_ptr *__gmp_const,
707                                           unsigned long, mpfr_rnd_t));
708
709__MPFR_DECLSPEC void mpfr_free_cache _MPFR_PROTO ((void));
710
711__MPFR_DECLSPEC int  mpfr_subnormalize _MPFR_PROTO ((mpfr_ptr, int,
712                                                     mpfr_rnd_t));
713
714__MPFR_DECLSPEC int  mpfr_strtofr _MPFR_PROTO ((mpfr_ptr, __gmp_const char *,
715                                                char **, int, mpfr_rnd_t));
716
717__MPFR_DECLSPEC size_t mpfr_custom_get_size   _MPFR_PROTO ((mpfr_prec_t));
718__MPFR_DECLSPEC void   mpfr_custom_init    _MPFR_PROTO ((void *, mpfr_prec_t));
719__MPFR_DECLSPEC void * mpfr_custom_get_significand _MPFR_PROTO ((mpfr_srcptr));
720__MPFR_DECLSPEC mpfr_exp_t mpfr_custom_get_exp  _MPFR_PROTO ((mpfr_srcptr));
721__MPFR_DECLSPEC void   mpfr_custom_move       _MPFR_PROTO ((mpfr_ptr, void *));
722__MPFR_DECLSPEC void   mpfr_custom_init_set   _MPFR_PROTO ((mpfr_ptr, int,
723                                             mpfr_exp_t, mpfr_prec_t, void *));
724__MPFR_DECLSPEC int    mpfr_custom_get_kind   _MPFR_PROTO ((mpfr_srcptr));
725
726#if defined (__cplusplus)
727}
728#endif
729
730/* DON'T USE THIS! (For MPFR-public macros only, see below.)
731   The mpfr_sgn macro uses the fact that __MPFR_EXP_NAN and __MPFR_EXP_ZERO
732   are the smallest values.
733   FIXME: In the following macros, the cast of an unsigned type with MSB set
734   to the signed type mpfr_exp_t yields an integer overflow, which can give
735   unexpected results with future compilers and aggressive optimisations.
736   Why not working only with signed types, using INT_MIN and LONG_MIN? */
737#if __GMP_MP_SIZE_T_INT
738#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+2))
739#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+1))
740#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+3))
741#else
742#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+2))
743#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+1))
744#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+3))
745#endif
746
747/* Define MPFR_USE_EXTENSION to avoid "gcc -pedantic" warnings. */
748#ifndef MPFR_EXTENSION
749# if defined(MPFR_USE_EXTENSION)
750#  define MPFR_EXTENSION __extension__
751# else
752#  define MPFR_EXTENSION
753# endif
754#endif
755
756/* Warning! This macro doesn't work with K&R C (e.g., compare the "gcc -E"
757   output with and without -traditional) and shouldn't be used internally.
758   For public use only, but see the MPFR manual. */
759#define MPFR_DECL_INIT(_x, _p)                                        \
760  MPFR_EXTENSION mp_limb_t __gmpfr_local_tab_##_x[((_p)-1)/GMP_NUMB_BITS+1]; \
761  MPFR_EXTENSION mpfr_t _x = {{(_p),1,__MPFR_EXP_NAN,__gmpfr_local_tab_##_x}}
762
763/* Fast access macros to replace function interface.
764   If the USER don't want to use the macro interface, let him make happy
765   even if it produces faster and smaller code. */
766#ifndef MPFR_USE_NO_MACRO
767
768/* Inlining theses functions is both faster and smaller */
769#define mpfr_nan_p(_x)      ((_x)->_mpfr_exp == __MPFR_EXP_NAN)
770#define mpfr_inf_p(_x)      ((_x)->_mpfr_exp == __MPFR_EXP_INF)
771#define mpfr_zero_p(_x)     ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
772#define mpfr_regular_p(_x)  ((_x)->_mpfr_exp >  __MPFR_EXP_INF)
773#define mpfr_sgn(_x)                                               \
774  ((_x)->_mpfr_exp < __MPFR_EXP_INF ?                              \
775   (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
776   MPFR_SIGN (_x))
777
778/* Prevent them from using as lvalues */
779#define MPFR_VALUE_OF(x)  (0 ? (x) : (x))
780#define mpfr_get_prec(_x) MPFR_VALUE_OF((_x)->_mpfr_prec)
781#define mpfr_get_exp(_x)  MPFR_VALUE_OF((_x)->_mpfr_exp)
782/* Note: if need be, the MPFR_VALUE_OF can be used for other expressions
783   (of any type). Thanks to Wojtek Lerch and Tim Rentsch for the idea. */
784
785#define mpfr_round(a,b) mpfr_rint((a), (b), MPFR_RNDNA)
786#define mpfr_trunc(a,b) mpfr_rint((a), (b), MPFR_RNDZ)
787#define mpfr_ceil(a,b)  mpfr_rint((a), (b), MPFR_RNDU)
788#define mpfr_floor(a,b) mpfr_rint((a), (b), MPFR_RNDD)
789
790#define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp((b),(i),0)
791#define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp((b),(i),0)
792#define mpfr_set(a,b,r)  mpfr_set4(a,b,r,MPFR_SIGN(b))
793#define mpfr_abs(a,b,r)  mpfr_set4(a,b,r,1)
794#define mpfr_copysign(a,b,c,r) mpfr_set4(a,b,r,MPFR_SIGN(c))
795#define mpfr_setsign(a,b,s,r) mpfr_set4(a,b,r,(s) ? -1 : 1)
796#define mpfr_signbit(x)  (MPFR_SIGN(x) < 0)
797#define mpfr_cmp(b, c)   mpfr_cmp3(b, c, 1)
798#define mpfr_mul_2exp(y,x,n,r) mpfr_mul_2ui((y),(x),(n),(r))
799#define mpfr_div_2exp(y,x,n,r) mpfr_div_2ui((y),(x),(n),(r))
800
801
802/* When using GCC, optimize certain common comparisons and affectations.
803   + Remove ICC since it defines __GNUC__ but produces a
804     huge number of warnings if you use this code.
805     VL: I couldn't reproduce a single warning when enabling these macros
806     with icc 10.1 20080212 on Itanium. But with this version, __ICC isn't
807     defined (__INTEL_COMPILER is, though), so that these macros are enabled
808     anyway. Checking with other ICC versions is needed. Possibly detect
809     whether warnings are produced or not with a configure test.
810   + Remove C++ too, since it complains too much. */
811/* Added casts to improve robustness in case of undefined behavior and
812   compiler extensions based on UB (in particular -fwrapv). MPFR doesn't
813   use such extensions, but these macros will be used by 3rd-party code,
814   where such extensions may be required.
815   Moreover casts to unsigned long have been added to avoid warnings in
816   programs that use MPFR and are compiled with -Wconversion; such casts
817   are OK since if X is a constant expression, then (unsigned long) X is
818   also a constant expression, so that the optimizations still work. The
819   warnings are probably related to the following two bugs:
820     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210
821     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470 (possibly a variant)
822   and the casts could be removed once these bugs are fixed.
823   Casts shouldn't be used on the generic calls (to the ..._2exp functions),
824   where implicit conversions are performed. Indeed, having at least one
825   implicit conversion in the macro allows the compiler to emit diagnostics
826   when normally expected, for instance in the following call:
827     mpfr_set_ui (x, "foo", MPFR_RNDN);
828   If this is not possible (for future macros), one of the tricks described
829   on http://groups.google.com/group/comp.std.c/msg/e92abd24bf9eaf7b could
830   be used. */
831#if defined (__GNUC__) && !defined(__ICC) && !defined(__cplusplus)
832#if (__GNUC__ >= 2)
833#undef mpfr_cmp_ui
834/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0.
835   But warning! mpfr_sgn is specified as a macro in the API, thus the macro
836   mustn't be used if side effects are possible, like here. */
837#define mpfr_cmp_ui(_f,_u)                                      \
838  (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ?        \
839   (mpfr_sgn) (_f) :                                            \
840   mpfr_cmp_ui_2exp ((_f), (_u), 0))
841#undef mpfr_cmp_si
842#define mpfr_cmp_si(_f,_s)                                      \
843  (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ?         \
844   mpfr_cmp_ui ((_f), (mpfr_ulong) (mpfr_long) (_s)) :          \
845   mpfr_cmp_si_2exp ((_f), (_s), 0))
846#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
847#undef mpfr_set_ui
848#define mpfr_set_ui(_f,_u,_r)                                   \
849  (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ?        \
850   __extension__ ({                                             \
851       mpfr_ptr _p = (_f);                                      \
852       _p->_mpfr_sign = 1;                                      \
853       _p->_mpfr_exp = __MPFR_EXP_ZERO;                         \
854       (mpfr_void) (_r); 0; }) :                                \
855   mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
856#endif
857#undef mpfr_set_si
858#define mpfr_set_si(_f,_s,_r)                                   \
859  (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ?         \
860   mpfr_set_ui ((_f), (mpfr_ulong) (mpfr_long) (_s), (_r)) :    \
861   mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
862#endif
863#endif
864
865/* Macro version of mpfr_stack interface for fast access */
866#define mpfr_custom_get_size(p) ((mpfr_size_t)                          \
867       (((p)+GMP_NUMB_BITS-1)/GMP_NUMB_BITS*sizeof (mp_limb_t)))
868#define mpfr_custom_init(m,p) do {} while (0)
869#define mpfr_custom_get_significand(x) ((mpfr_void*)((x)->_mpfr_d))
870#define mpfr_custom_get_exp(x) ((x)->_mpfr_exp)
871#define mpfr_custom_move(x,m) do { ((x)->_mpfr_d = (mp_limb_t*)(m)); } while (0)
872#define mpfr_custom_init_set(x,k,e,p,m) do {                   \
873  mpfr_ptr _x = (x);                                           \
874  mpfr_exp_t _e;                                               \
875  mpfr_kind_t _t;                                              \
876  mpfr_int _s, _k;                                             \
877  _k = (k);                                                    \
878  if (_k >= 0)  {                                              \
879    _t = (mpfr_kind_t) _k;                                     \
880    _s = 1;                                                    \
881  } else {                                                     \
882    _t = (mpfr_kind_t) -k;                                     \
883    _s = -1;                                                   \
884  }                                                            \
885  _e = _t == MPFR_REGULAR_KIND ? (e) :                         \
886    _t == MPFR_NAN_KIND ? __MPFR_EXP_NAN :                     \
887    _t == MPFR_INF_KIND ? __MPFR_EXP_INF : __MPFR_EXP_ZERO;    \
888  _x->_mpfr_prec = (p);                                        \
889  _x->_mpfr_sign = _s;                                         \
890  _x->_mpfr_exp  = _e;                                         \
891  _x->_mpfr_d    = (mp_limb_t*) (m);                           \
892 } while (0)
893#define mpfr_custom_get_kind(x)                                         \
894  ( (x)->_mpfr_exp >  __MPFR_EXP_INF ?                                  \
895    (mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (x)                        \
896  : (x)->_mpfr_exp == __MPFR_EXP_INF ?                                  \
897    (mpfr_int) MPFR_INF_KIND * MPFR_SIGN (x)                            \
898  : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (mpfr_int) MPFR_NAN_KIND         \
899  : (mpfr_int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
900
901
902#endif /* MPFR_USE_NO_MACRO */
903
904/* Theses are defined to be macros */
905#define mpfr_init_set_si(x, i, rnd) \
906 ( mpfr_init(x), mpfr_set_si((x), (i), (rnd)) )
907#define mpfr_init_set_ui(x, i, rnd) \
908 ( mpfr_init(x), mpfr_set_ui((x), (i), (rnd)) )
909#define mpfr_init_set_d(x, d, rnd) \
910 ( mpfr_init(x), mpfr_set_d((x), (d), (rnd)) )
911#define mpfr_init_set_ld(x, d, rnd) \
912 ( mpfr_init(x), mpfr_set_ld((x), (d), (rnd)) )
913#define mpfr_init_set_z(x, i, rnd) \
914 ( mpfr_init(x), mpfr_set_z((x), (i), (rnd)) )
915#define mpfr_init_set_q(x, i, rnd) \
916 ( mpfr_init(x), mpfr_set_q((x), (i), (rnd)) )
917#define mpfr_init_set(x, y, rnd) \
918 ( mpfr_init(x), mpfr_set((x), (y), (rnd)) )
919#define mpfr_init_set_f(x, y, rnd) \
920 ( mpfr_init(x), mpfr_set_f((x), (y), (rnd)) )
921
922/* Compatibility layer -- obsolete functions and macros */
923#define mpfr_cmp_abs mpfr_cmpabs
924#define mpfr_round_prec(x,r,p) mpfr_prec_round(x,p,r)
925#define __gmp_default_rounding_mode (mpfr_get_default_rounding_mode())
926#define __mpfr_emin (mpfr_get_emin())
927#define __mpfr_emax (mpfr_get_emax())
928#define __mpfr_default_fp_bit_precision (mpfr_get_default_fp_bit_precision())
929#define MPFR_EMIN_MIN mpfr_get_emin_min()
930#define MPFR_EMIN_MAX mpfr_get_emin_max()
931#define MPFR_EMAX_MIN mpfr_get_emax_min()
932#define MPFR_EMAX_MAX mpfr_get_emax_max()
933#define mpfr_version (mpfr_get_version())
934#ifndef mpz_set_fr
935# define mpz_set_fr mpfr_get_z
936#endif
937#define mpfr_add_one_ulp(x,r) \
938 (mpfr_sgn (x) > 0 ? mpfr_nextabove (x) : mpfr_nextbelow (x))
939#define mpfr_sub_one_ulp(x,r) \
940 (mpfr_sgn (x) > 0 ? mpfr_nextbelow (x) : mpfr_nextabove (x))
941#define mpfr_get_z_exp mpfr_get_z_2exp
942#define mpfr_custom_get_mantissa mpfr_custom_get_significand
943
944#endif /* __MPFR_H*/
945