Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mpfr-impl.hpp
1 /* Utilities for MPFR developers, not exported.
2 
3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009
4  Free Software Foundation, Inc.
5 
6 This file is part of the MPFR Library.
7 
8 The MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3.0 of the License, or (at your
11 option) any later version.
12 
13 The MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with the MPFR Library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22 
23 #ifndef __MPFR_IMPL_H__
24 #define __MPFR_IMPL_H__
25 
26 /* Include stdio.h iff we are debugging or we want to check */
27 #if defined(DEBUG) || defined(WANT_ASSERT)
28 # include <stdio.h>
29 #endif
30 
31 /* Check if we are inside a build of MPFR or inside the test suite.
32  This is needed in mpfr.h to export or import the functions.
33  It matters only for Windows DLL */
34 #ifndef __MPFR_TEST_H__
35 # define __MPFR_WITHIN_MPFR 1
36 #endif
37 
38 /******************************************************
39  ****************** Include files *********************
40  ******************************************************/
41 
42 /* Include 'config.h' before using ANY configure macros if needed
43  NOTE: It isn't MPFR 'config.h', but GMP's one! */
44 #if defined(FEELPP_HAS_CONFIG_H)
45 #if FEELPP_HAS_CONFIG_H
46 //#include "config.h"
47 #endif
48 #endif
49 
50 #ifdef MPFR_FEELPP_HAS_GMP_IMPL /* Build with gmp internals*/
51 
52 # ifndef __GMP_H__
53 # include "gmp.h"
54 # endif
55 # ifndef __GMP_IMPL_H__
56 # include "gmp-impl.h"
57 # endif
58 # ifdef MPFR_NEED_LONGLONG_H
59 # include "longlong.h"
60 # endif
61 # ifndef __MPFR_H
62 # include "mpfr.h"
63 # endif
64 
65 #else /* Build without gmp internals */
66 
67 # ifndef __GMP_H__
68 # include "gmp.h"
69 # endif
70 # ifndef __MPFR_H
71 # include "mpfr.h"
72 # endif
73 # ifndef __GMPFR_GMP_H__
74 # include <feel/feelcore/mpfr-gmp.hpp>
75 # endif
76 # ifdef MPFR_NEED_LONGLONG_H
77 # include "mpfr-longlong.h"
78 # endif
79 
80 #endif
81 #undef MPFR_NEED_LONGLONG_H
82 
83 
84 /******************************************************
85  ***************** Detection macros *******************
86  ******************************************************/
87 
88 /* Macros to detect STDC, GCC, GLIBC, GMP and ICC version */
89 #if defined(__STDC_VERSION__)
90 # define __MPFR_STDC(version) (__STDC_VERSION__>=(version))
91 #elif defined(__STDC__)
92 # define __MPFR_STDC(version) (0 == (version))
93 #else
94 # define __MPFR_STDC(version) 0
95 #endif
96 
97 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__ICC)
98 # define __MPFR_GNUC(a, i) \
99  (MPFR_VERSION_NUM(__GNUC__,__GNUC_MINOR__,0)>=MPFR_VERSION_NUM(a,i,0))
100 #else
101 # define __MPFR_GNUC(a, i) 0
102 #endif
103 
104 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
105 # define __MPFR_GLIBC(a, i) \
106  (MPFR_VERSION_NUM(__GLIBC__,__GLIBC_MINOR__,0)>=MPFR_VERSION_NUM(a,i,0))
107 #else
108 # define __MPFR_GLIBC(a, i) 0
109 #endif
110 
111 #if defined(__GNU_MP_VERSION)&&defined(__GNU_MP_VERSION_MINOR)&&defined(__GNU_MP_VERSION_PATCHLEVEL)
112 # define __MPFR_GMP(a, b, c) \
113 (MPFR_VERSION_NUM(__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR,__GNU_MP_VERSION_PATCHLEVEL) >= MPFR_VERSION_NUM(a,b,c))
114 #else
115 # define __MPFR_GMP(a, b, c) 0
116 #endif
117 
118 #if defined(__ICC)
119 # define __MPFR_ICC(a,b,c) (__ICC >= (a)*100+(b)*10+c)
120 #else
121 # define __MPFR_ICC(a,b,c) 0
122 #endif
123 
124 
125 
126 /******************************************************
127  ******************** Check GMP ***********************
128  ******************************************************/
129 
130 #if !__MPFR_GMP(4,1,0)
131 # error "GMP 4.1.0 or newer needed"
132 #endif
133 
134 #if GMP_NAIL_BITS != 0
135 # error "MPFR doesn't support nonzero values of GMP_NAIL_BITS"
136 #endif
137 
138 #if (BITS_PER_MP_LIMB<32) || (BITS_PER_MP_LIMB & (BITS_PER_MP_LIMB - 1))
139 # error "BITS_PER_MP_LIMB must be a power of 2, and >= 32"
140 #endif
141 
142 #if BITS_PER_MP_LIMB == 16
143 # define MPFR_LOG2_BITS_PER_MP_LIMB 4
144 #elif BITS_PER_MP_LIMB == 32
145 # define MPFR_LOG2_BITS_PER_MP_LIMB 5
146 #elif BITS_PER_MP_LIMB == 64
147 # define MPFR_LOG2_BITS_PER_MP_LIMB 6
148 #elif BITS_PER_MP_LIMB == 128
149 # define MPFR_LOG2_BITS_PER_MP_LIMB 7
150 #elif BITS_PER_MP_LIMB == 256
151 # define MPFR_LOG2_BITS_PER_MP_LIMB 8
152 #else
153 # error "Can't compute log2(BITS_PER_MP_LIMB)"
154 #endif
155 
156 /* mpn_sub_nc is internal but may be defined in the header
157  but not in the library! That's why we may need to overide it.*/
158 #ifndef MPFR_FEELPP_HAS_MPN_SUB_NC
159 mp_limb_t mpfr_sub_nc _MPFR_PROTO ( ( mp_ptr, mp_srcptr, mp_srcptr, mp_size_t,
160  mp_limb_t ) );
161 #undef mpn_sub_nc
162 #define mpn_sub_nc mpfr_sub_nc
163 #endif
164 
165 #if __MPFR_GNUC(3,0) || __MPFR_ICC(8,1,0)
166 # define MPFR_NORETURN_ATTR __attribute__ ((noreturn))
167 # define MPFR_CONST_ATTR __attribute__ ((const))
168 #else
169 # define MPFR_NORETURN_ATTR
170 # define MPFR_CONST_ATTR
171 #endif
172 
173 /******************************************************
174  ************* Global Internal Variables **************
175  ******************************************************/
176 
177 #ifdef MPFR_USE_THREAD_SAFE
178 # if __MPFR_GNUC(3,3) || __MPFR_ICC(8,1,0)
179 # define MPFR_THREAD_ATTR __thread
180 # else
181 # error "Can't build MPFR as thread safe"
182 # endif
183 #else
184 # define MPFR_THREAD_ATTR
185 #endif
186 
187 #if defined (__cplusplus)
188 extern "C" {
189 #endif
190 
191  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR unsigned int __gmpfr_flags;
192  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mp_exp_t __gmpfr_emin;
193  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mp_exp_t __gmpfr_emax;
194  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mp_prec_t __gmpfr_default_fp_bit_precision;
195  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mpfr_rnd_t __gmpfr_default_rounding_mode;
196  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_pi;
197  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_log2;
198  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_euler;
199  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_catalan;
200 
201  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR const mpfr_t __gmpfr_one;
202  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR const mpfr_t __gmpfr_two;
203  __MPFR_DECLSPEC extern MPFR_THREAD_ATTR const mpfr_t __gmpfr_four;
204 
205 
206 #if defined (__cplusplus)
207 }
208 #endif
209 
210 /* Flags of __gmpfr_flags */
211 #define MPFR_FLAGS_UNDERFLOW 1
212 #define MPFR_FLAGS_OVERFLOW 2
213 #define MPFR_FLAGS_NAN 4
214 #define MPFR_FLAGS_INEXACT 8
215 #define MPFR_FLAGS_ERANGE 16
216 #define MPFR_FLAGS_ALL 31
217 
218 /* Replace some commun functions for direct access to the global vars */
219 #define mpfr_get_emin() (__gmpfr_emin + 0)
220 #define mpfr_get_emax() (__gmpfr_emax + 0)
221 #define mpfr_get_default_rounding_mode() (__gmpfr_default_rounding_mode + 0)
222 #define mpfr_get_default_prec() (__gmpfr_default_fp_bit_precision + 0)
223 
224 #define mpfr_clear_flags() \
225  ((void) (__gmpfr_flags = 0))
226 #define mpfr_clear_underflow() \
227  ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_UNDERFLOW))
228 #define mpfr_clear_overflow() \
229  ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_OVERFLOW))
230 #define mpfr_clear_nanflag() \
231  ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_NAN))
232 #define mpfr_clear_inexflag() \
233  ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_INEXACT))
234 #define mpfr_clear_erangeflag() \
235  ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE))
236 #define mpfr_underflow_p() \
237  ((int) (__gmpfr_flags & MPFR_FLAGS_UNDERFLOW))
238 #define mpfr_overflow_p() \
239  ((int) (__gmpfr_flags & MPFR_FLAGS_OVERFLOW))
240 #define mpfr_nanflag_p() \
241  ((int) (__gmpfr_flags & MPFR_FLAGS_NAN))
242 #define mpfr_inexflag_p() \
243  ((int) (__gmpfr_flags & MPFR_FLAGS_INEXACT))
244 #define mpfr_erangeflag_p() \
245  ((int) (__gmpfr_flags & MPFR_FLAGS_ERANGE))
246 
247 
248 /******************************************************
249  ******************** Assertions **********************
250  ******************************************************/
251 
252 /* Compile with -DWANT_ASSERT to check all assert statements */
253 
254 /* Note: do not use GMP macros ASSERT_ALWAYS and ASSERT as they are not
255  expressions, and as a consequence, they cannot be used in a for(),
256  with a comma operator and so on. */
257 
258 /* MPFR_ASSERTN(expr): assertions that should always be checked */
259 #define MPFR_ASSERTN(expr) \
260  ((void) ((MPFR_UNLIKELY(expr)) || MPFR_UNLIKELY( (ASSERT_FAIL(expr),0) )))
261 
262 /* MPFR_ASSERTD(expr): assertions that should be checked when testing */
263 #ifdef WANT_ASSERT
264 # define MPFR_EXP_CHECK 1
265 # define MPFR_ASSERTD(expr) MPFR_ASSERTN (expr)
266 #else
267 # define MPFR_ASSERTD(expr) ((void) 0)
268 #endif
269 
270 /* Check if the args are correct */
271 /* Can't be used since TMP variables are not correct */
272 #define MPFR_CHECK1(x,r) \
273  MPFR_ASSERTD(mpfr_check(x) && GMP_RNDN <= r && r <= GMP_RNDD)
274 #define MPFR_CHECK2(x,y,r) \
275  MPFR_ASSERTD(mpfr_check(x) && mpfr_check(y) && GMP_RNDN <= r && r <= GMP_RNDD)
276 #define MPFR_CHECK3(x,y,z,r) \
277  MPFR_ASSERTD(mpfr_check(x) && mpfr_check(y) && mpfr_check(z) && \
278  GMP_RNDN <= r && r <= GMP_RNDD)
279 
280 /* Code to deal with impossible
281  WARNING: It doesn't use do { } while (0) for Insure++*/
282 #define MPFR_RET_NEVER_GO_HERE() {MPFR_ASSERTN(0); return 0;}
283 
284 
285 
286 /******************************************************
287  ****************** double macros *********************
288  ******************************************************/
289 
290 /* Definition of constants */
291 #define LOG2 0.69314718055994528622 /* log(2) rounded to zero on 53 bits */
292 #define ALPHA 4.3191365662914471407 /* a+2 = a*log(a), rounded to +infinity */
293 #define EXPM1 0.36787944117144227851 /* exp(-1), rounded to zero */
294 
295 /* MPFR_DOUBLE_SPEC = 1 if the C type 'double' corresponds to IEEE-754
296  double precision, 0 if it doesn't, and undefined if one doesn't know.
297  On all the tested machines, MPFR_DOUBLE_SPEC = 1. To have this macro
298  defined here, #include <float.h> is needed. If need be, other values
299  could be defined for other specs (once they are known). */
300 #if !defined(MPFR_DOUBLE_SPEC) && defined(FLT_RADIX) && \
301  defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP) && defined(DBL_MAX_EXP)
302 # if FLT_RADIX == 2 && DBL_MANT_DIG == 53 && \
303  DBL_MIN_EXP == -1021 && DBL_MAX_EXP == 1024
304 # define MPFR_DOUBLE_SPEC 1
305 # else
306 # define MPFR_DOUBLE_SPEC 0
307 # endif
308 #endif
309 
310 /* Debug non IEEE floats */
311 #ifdef XDEBUG
312 # undef _GMP_IEEE_FLOATS
313 #endif
314 #ifndef _GMP_IEEE_FLOATS
315 # define _GMP_IEEE_FLOATS 0
316 #endif
317 
318 #ifndef IEEE_DBL_MANT_DIG
319 #define IEEE_DBL_MANT_DIG 53
320 #endif
321 #define MPFR_LIMBS_PER_DOUBLE ((IEEE_DBL_MANT_DIG-1)/BITS_PER_MP_LIMB+1)
322 
323 /* Visual C++ doesn't support +1.0/.00, -1.0/0.0 and 0.0/0.0
324  at compile time. */
325 #if defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)
326 static double double_zero = 0.0;
327 # define DBL_NAN (double_zero/double_zero)
328 # define DBL_POS_INF ((double) 1.0/double_zero)
329 # define DBL_NEG_INF ((double)-1.0/double_zero)
330 #else
331 # define DBL_POS_INF ((double) 1.0/0.0)
332 # define DBL_NEG_INF ((double)-1.0/0.0)
333 # define DBL_NAN ((double) 0.0/0.0)
334 #endif
335 
336 /* for x of type ieee_double_extract */
337 #if _GMP_IEEE_FLOATS
338 typedef union ieee_double_extract Ieee_double_extract;
339 
340 # define DOUBLE_ISNANorINF(x) (((Ieee_double_extract *)&(x))->s.exp == 0x7ff)
341 # define DOUBLE_ISINF(x) (DOUBLE_ISNANorINF(x) && \
342  (((Ieee_double_extract *)&(x))->s.manl == 0) && \
343  (((Ieee_double_extract *)&(x))->s.manh == 0))
344 # define DOUBLE_ISNAN(x) (DOUBLE_ISNANorINF(x) && \
345  ((((Ieee_double_extract *)&(x))->s.manl != 0) || \
346  (((Ieee_double_extract *)&(x))->s.manh != 0)))
347 #else
348 # define DOUBLE_ISINF(x) ((x) > DBL_MAX || (x) < -DBL_MAX)
349 # if MPFR_NANISNAN
350 /* Avoid MIPSpro / IRIX64 (incorrect) optimizations.
351  The + must not be replaced by a ||. */
352 # define DOUBLE_ISNAN(x) (!(((x) >= 0.0) + ((x) <= 0.0)))
353 # else
354 # define DOUBLE_ISNAN(x) ((x) != (x))
355 # endif
356 #endif
357 
358 
359 
360 /******************************************************
361  *************** Long double macros *******************
362  ******************************************************/
363 
364 /* We try to get the exact value of the precision of long double
365  (provided by the implementation) in order to provide correct
366  rounding in this case (not guaranteed if the C implementation
367  does not have an adequate long double arithmetic). Note that
368  it may be lower than the precision of some numbers that can
369  be represented in a long double; e.g. on FreeBSD/x86, it is
370  53 because the processor is configured to round in double
371  precision (even when using the long double type -- this is a
372  limitation of the x87 arithmetic), and on Mac OS X, it is 106
373  because the implementation is a double-double arithmetic.
374  Otherwise (e.g. in base 10), we get an upper bound of the
375  precision, and correct rounding isn't currently provided.
376 */
377 #if LDBL_MANT_DIG && FLT_RADIX == 2
378 # define MPFR_LDBL_MANT_DIG LDBL_MANT_DIG
379 #else
380 # define MPFR_LDBL_MANT_DIG \
381  (sizeof(long double)*BITS_PER_MP_LIMB/sizeof(mp_limb_t))
382 #endif
383 #define MPFR_LIMBS_PER_LONG_DOUBLE \
384  ((sizeof(long double)-1)/sizeof(mp_limb_t)+1)
385 
386 /* LONGDOUBLE_NAN_ACTION executes the code "action" if x is a NaN. */
387 
388 /* On hppa2.0n-hp-hpux10 with the unbundled HP cc, the test x!=x on a NaN
389  has been seen false, meaning NaNs are not detected. This seemed to
390  happen only after other comparisons, not sure what's really going on. In
391  any case we can pick apart the bytes to identify a NaN. */
392 #ifdef FEELPP_HAS_LDOUBLE_IEEE_QUAD_BIG
393 # define LONGDOUBLE_NAN_ACTION(x, action) \
394  do { \
395  union { \
396  long double ld; \
397  struct { \
398  unsigned int sign : 1; \
399  unsigned int exp : 15; \
400  unsigned int man3 : 16; \
401  unsigned int man2 : 32; \
402  unsigned int man1 : 32; \
403  unsigned int man0 : 32; \
404  } s; \
405  } u; \
406  u.ld = (x); \
407  if (u.s.exp == 0x7FFFL \
408  && (u.s.man0 | u.s.man1 | u.s.man2 | u.s.man3) != 0) \
409  { action; } \
410  } while (0)
411 #endif
412 
413 /* Under IEEE rules, NaN is not equal to anything, including itself.
414  "volatile" here stops "cc" on mips64-sgi-irix6.5 from optimizing away
415  x!=x. */
416 #ifndef LONGDOUBLE_NAN_ACTION
417 # define LONGDOUBLE_NAN_ACTION(x, action) \
418  do { \
419  volatile long double __x = LONGDOUBLE_VOLATILE (x); \
420  if ((x) != __x) \
421  { action; } \
422  } while (0)
423 # define WANT_LONGDOUBLE_VOLATILE 1
424 #endif
425 
426 /* If we don't have a proper "volatile" then volatile is #defined to empty,
427  in this case call through an external function to stop the compiler
428  optimizing anything. */
429 #ifdef WANT_LONGDOUBLE_VOLATILE
430 # ifdef volatile
431 __MPFR_DECLSPEC long double __gmpfr_longdouble_volatile _MPFR_PROTO ( ( long double ) ) MPFR_CONST_ATTR;
432 # define LONGDOUBLE_VOLATILE(x) (__gmpfr_longdouble_volatile (x))
433 # define WANT_GMPFR_LONGDOUBLE_VOLATILE 1
434 # else
435 # define LONGDOUBLE_VOLATILE(x) (x)
436 # endif
437 #endif
438 
439 /* Some special case for IEEE_EXT Litle Endian */
440 #if FEELPP_HAS_LDOUBLE_IEEE_EXT_LITTLE
441 
442 typedef union
443 {
444  long double ld;
445  struct
446  {
447  unsigned int manl : 32;
448  unsigned int manh : 32;
449  unsigned int expl : 8 ;
450  unsigned int exph : 7;
451  unsigned int sign : 1;
452  } s;
453 } mpfr_long_double_t;
454 
455 /* #undef MPFR_LDBL_MANT_DIG */
456 #undef MPFR_LIMBS_PER_LONG_DOUBLE
457 /* #define MPFR_LDBL_MANT_DIG 64 */
458 #define MPFR_LIMBS_PER_LONG_DOUBLE ((64-1)/BITS_PER_MP_LIMB+1)
459 
460 #endif
461 
462 /******************************************************
463  **************** mpfr_t properties *******************
464  ******************************************************/
465 
466 #define MPFR_PREC(x) ((x)->_mpfr_prec)
467 #define MPFR_EXP(x) ((x)->_mpfr_exp)
468 #define MPFR_MANT(x) ((x)->_mpfr_d)
469 #define MPFR_LIMB_SIZE(x) ((MPFR_PREC((x))-1)/BITS_PER_MP_LIMB+1)
470 
471 #if _MPFR_PREC_FORMAT == 1
472 # define MPFR_INTPREC_MAX (USHRT_MAX & ~(unsigned int) (BITS_PER_MP_LIMB - 1))
473 #elif _MPFR_PREC_FORMAT == 2
474 # define MPFR_INTPREC_MAX (UINT_MAX & ~(unsigned int) (BITS_PER_MP_LIMB - 1))
475 #elif _MPFR_PREC_FORMAT == 3
476 # define MPFR_INTPREC_MAX (ULONG_MAX & ~(unsigned long) (BITS_PER_MP_LIMB - 1))
477 #else
478 # error "Invalid MPFR Prec format"
479 #endif
480 
481 
482 
483 /******************************************************
484  ***************** exponent limits ********************
485  ******************************************************/
486 
487 /* Defined limits and unsigned type of exponent */
488 #if __GMP_MP_SIZE_T_INT == 1
489 typedef unsigned int mpfr_uexp_t;
490 # define MPFR_EXP_MAX (INT_MAX)
491 # define MPFR_EXP_MIN (INT_MIN)
492 #else
493 typedef unsigned long int mpfr_uexp_t;
494 # define MPFR_EXP_MAX (LONG_MAX)
495 # define MPFR_EXP_MIN (LONG_MIN)
496 #endif
497 #ifndef mp_exp_unsigned_t
498 # define mp_exp_unsigned_t mpfr_uexp_t
499 #endif
500 
501 /* Invalid exponent value (to track bugs...) */
502 #define MPFR_EXP_INVALID \
503  ((mp_exp_t) 1 << (BITS_PER_MP_LIMB*sizeof(mp_exp_t)/sizeof(mp_limb_t)-2))
504 
505 /* Definition of the intervals of the exponent limits */
506 #undef MPFR_EMIN_MIN
507 #undef MPFR_EMIN_MAX
508 #undef MPFR_EMAX_MIN
509 #undef MPFR_EMAX_MAX
510 #define MPFR_EMIN_MIN (1-MPFR_EXP_INVALID)
511 #define MPFR_EMIN_MAX (MPFR_EXP_INVALID-1)
512 #define MPFR_EMAX_MIN (1-MPFR_EXP_INVALID)
513 #define MPFR_EMAX_MAX (MPFR_EXP_INVALID-1)
514 
515 /* Use MPFR_GET_EXP and MPFR_SET_EXP instead of MPFR_EXP directly,
516  unless when the exponent may be out-of-range, for instance when
517  setting the exponent before calling mpfr_check_range.
518  MPFR_EXP_CHECK is defined when WANT_ASSERT is defined, but if you
519  don't use WANT_ASSERT (for speed reasons), you can still define
520  MPFR_EXP_CHECK by setting -DMPFR_EXP_CHECK in $CFLAGS. */
521 
522 #ifdef MPFR_EXP_CHECK
523 # define MPFR_GET_EXP(x) (mpfr_get_exp) (x)
524 # define MPFR_SET_EXP(x, exp) MPFR_ASSERTN (!mpfr_set_exp ((x), (exp)))
525 # define MPFR_SET_INVALID_EXP(x) ((void) (MPFR_EXP (x) = MPFR_EXP_INVALID))
526 #else
527 # define MPFR_GET_EXP(x) MPFR_EXP (x)
528 # define MPFR_SET_EXP(x, exp) ((void) (MPFR_EXP (x) = (exp)))
529 # define MPFR_SET_INVALID_EXP(x) ((void) 0)
530 #endif
531 
532 
533 
534 /******************************************************
535  ********** Singular Values (NAN, INF, ZERO) **********
536  ******************************************************/
537 
538 /*
539  * Clear flags macros are still defined and should be still used
540  * since the functions must not assume the internal format.
541  * How to deal with special values ?
542  * 1. Check if is a special value (Zero, Nan, Inf) wiht MPFR_IS_SINGULAR
543  * 2. Deal with the special value with MPFR_IS_NAN, MPFR_IS_INF, etc
544  * 3. Else clear the flags of the dest (it must be done after since src
545  * may be also the dest!)
546  * MPFR_SET_INF, MPFR_SET_NAN, MPFR_SET_ZERO must clear by
547  * themselves the other flags.
548  */
549 
550 /* Enum special value of exponent.*/
551 # define MPFR_EXP_ZERO (MPFR_EXP_MIN+1)
552 # define MPFR_EXP_NAN (MPFR_EXP_MIN+2)
553 # define MPFR_EXP_INF (MPFR_EXP_MIN+3)
554 
555 #define MPFR_CLEAR_FLAGS(x)
556 
557 #define MPFR_IS_NAN(x) (MPFR_EXP(x) == MPFR_EXP_NAN)
558 #define MPFR_SET_NAN(x) (MPFR_EXP(x) = MPFR_EXP_NAN)
559 #define MPFR_IS_INF(x) (MPFR_EXP(x) == MPFR_EXP_INF)
560 #define MPFR_SET_INF(x) (MPFR_EXP(x) = MPFR_EXP_INF)
561 #define MPFR_IS_ZERO(x) (MPFR_EXP(x) == MPFR_EXP_ZERO)
562 #define MPFR_SET_ZERO(x) (MPFR_EXP(x) = MPFR_EXP_ZERO)
563 #define MPFR_NOTZERO(x) (MPFR_EXP(x) != MPFR_EXP_ZERO)
564 
565 #define MPFR_IS_FP(x) (!MPFR_IS_NAN(x) && !MPFR_IS_INF(x))
566 #define MPFR_IS_SINGULAR(x) (MPFR_EXP(x) <= MPFR_EXP_INF)
567 #define MPFR_IS_PURE_FP(x) (!MPFR_IS_SINGULAR(x))
568 
569 #define MPFR_ARE_SINGULAR(x,y) \
570  (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)) || MPFR_UNLIKELY(MPFR_IS_SINGULAR(y)))
571 
572 
573 
574 /******************************************************
575  ********************* Sign Macros ********************
576  ******************************************************/
577 
578 #define MPFR_SIGN_POS (1)
579 #define MPFR_SIGN_NEG (-1)
580 
581 #define MPFR_IS_STRICTPOS(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) > 0)
582 #define MPFR_IS_STRICTNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) < 0)
583 
584 #define MPFR_IS_NEG(x) (MPFR_SIGN(x) < 0)
585 #define MPFR_IS_POS(x) (MPFR_SIGN(x) > 0)
586 
587 #define MPFR_SET_POS(x) (MPFR_SIGN(x) = MPFR_SIGN_POS)
588 #define MPFR_SET_NEG(x) (MPFR_SIGN(x) = MPFR_SIGN_NEG)
589 
590 #define MPFR_CHANGE_SIGN(x) (MPFR_SIGN(x) = -MPFR_SIGN(x))
591 #define MPFR_SET_SAME_SIGN(x, y) (MPFR_SIGN(x) = MPFR_SIGN(y))
592 #define MPFR_SET_OPPOSITE_SIGN(x, y) (MPFR_SIGN(x) = -MPFR_SIGN(y))
593 #define MPFR_ASSERT_SIGN(s) \
594  (MPFR_ASSERTD((s) == MPFR_SIGN_POS || (s) == MPFR_SIGN_NEG))
595 #define MPFR_SET_SIGN(x, s) \
596  (MPFR_ASSERT_SIGN(s), MPFR_SIGN(x) = s)
597 #define MPFR_IS_POS_SIGN(s1) (s1 > 0)
598 #define MPFR_IS_NEG_SIGN(s1) (s1 < 0)
599 #define MPFR_MULT_SIGN(s1, s2) ((s1) * (s2))
600 /* Transform a sign to 1 or -1 */
601 #define MPFR_FROM_SIGN_TO_INT(s) (s)
602 #define MPFR_INT_SIGN(x) MPFR_FROM_SIGN_TO_INT(MPFR_SIGN(x))
603 
604 
605 
606 /******************************************************
607  ***************** Ternary Value Macros ***************
608  ******************************************************/
609 
610 /* Special inexact value */
611 #define MPFR_EVEN_INEX 2
612 
613 /* When returning the ternary inexact value, ALWAYS use one of the
614  following two macros, unless the flag comes from another function
615  returning the ternary inexact value */
616 #define MPFR_RET(I) return \
617  (I) ? ((__gmpfr_flags |= MPFR_FLAGS_INEXACT), (I)) : 0
618 #define MPFR_RET_NAN return (__gmpfr_flags |= MPFR_FLAGS_NAN), 0
619 
620 #define MPFR_SET_ERANGE() (__gmpfr_flags |= MPFR_FLAGS_ERANGE)
621 
622 
623 
624 /******************************************************
625  ************** Rounding mode macros *****************
626  ******************************************************/
627 
628 /* We want to test this :
629  * (rnd == GMP_RNDU && test) || (rnd == RNDD && !test)
630  * ie it transforms RNDU or RNDD to Away or Zero according to the sign */
631 #define MPFR_IS_RNDUTEST_OR_RNDDNOTTEST(rnd, test) \
632  (((rnd) + (test)) == GMP_RNDD)
633 
634 /* We want to test if rnd = Zero, or Away.
635  'test' is true iff negative. */
636 #define MPFR_IS_LIKE_RNDZ(rnd, test) \
637  ((rnd==GMP_RNDZ) || MPFR_IS_RNDUTEST_OR_RNDDNOTTEST (rnd, test))
638 
639 /* Invert a rounding mode */
640 #define MPFR_INVERT_RND(rnd) ((rnd == GMP_RNDU) ? GMP_RNDD : \
641  ((rnd == GMP_RNDD) ? GMP_RNDU : rnd))
642 
643 /* Transform RNDU and RNDD to RNDA or RNDZ */
644 #define MPFR_UPDATE_RND_MODE(rnd, test) \
645  do { \
646  if (MPFR_UNLIKELY(MPFR_IS_RNDUTEST_OR_RNDDNOTTEST(rnd, test))) \
647  rnd = GMP_RNDZ; \
648  } while (0)
649 
650 
651 
652 /******************************************************
653  ******************* Limb Macros **********************
654  ******************************************************/
655 
656 /* Definition of MPFR_LIMB_HIGHBIT */
657 #if defined(GMP_LIMB_HIGHBIT)
658 # define MPFR_LIMB_HIGHBIT GMP_LIMB_HIGHBIT
659 #elif defined(MP_LIMB_T_HIGHBIT)
660 # define MPFR_LIMB_HIGHBIT MP_LIMB_T_HIGHBIT
661 #else
662 # error "Neither GMP_LIMB_HIGHBIT nor MP_LIMB_T_HIGHBIT defined in GMP"
663 #endif
664 
665 /* Mask to get the Most Significent Bit of a limb */
666 #define MPFR_LIMB_MSB(l) ((l)&MPFR_LIMB_HIGHBIT)
667 
668 /* Definition of MPFR_LIMB_ONE & MPFR_LIMB_ZERO*/
669 #ifdef CNST_LIMB
670 # define MPFR_LIMB_ONE CNST_LIMB(1)
671 # define MPFR_LIMB_ZERO CNST_LIMB(0)
672 #else
673 # define MPFR_LIMB_ONE ((mp_limb_t) 1L)
674 # define MPFR_LIMB_ZERO ((mp_limb_t) 0L)
675 #endif
676 
677 /* Mask for the low 's' bits of a limb */
678 #define MPFR_LIMB_MASK(s) ((MPFR_LIMB_ONE<<(s))-MPFR_LIMB_ONE)
679 
680 
681 
682 /******************************************************
683  ********************** Memory ************************
684  ******************************************************/
685 
686 /* Heap Memory gestion */
687 typedef union
688 {
689  mp_size_t s;
690  mp_limb_t l;
691 } mpfr_size_limb_t;
692 #define MPFR_GET_ALLOC_SIZE(x) \
693  ( ((mp_size_t*) MPFR_MANT(x))[-1] + 0)
694 #define MPFR_SET_ALLOC_SIZE(x, n) \
695  ( ((mp_size_t*) MPFR_MANT(x))[-1] = n)
696 #define MPFR_MALLOC_SIZE(s) \
697  ( sizeof(mpfr_size_limb_t) + BYTES_PER_MP_LIMB * ((size_t) s) )
698 #define MPFR_SET_MANT_PTR(x,p) \
699  (MPFR_MANT(x) = (mp_limb_t*) ((mpfr_size_limb_t*) p + 1))
700 #define MPFR_GET_REAL_PTR(x) \
701  ((mp_limb_t*) ((mpfr_size_limb_t*) MPFR_MANT(x) - 1))
702 
703 /* Temporary memory gestion */
704 #ifndef TMP_SALLOC
705 /* GMP 4.1.x or below or internals */
706 #define MPFR_TMP_DECL TMP_DECL
707 #define MPFR_TMP_MARK TMP_MARK
708 #define MPFR_TMP_ALLOC TMP_ALLOC
709 #define MPFR_TMP_FREE TMP_FREE
710 #else
711 #define MPFR_TMP_DECL(x) TMP_DECL
712 #define MPFR_TMP_MARK(x) TMP_MARK
713 #define MPFR_TMP_ALLOC(s) TMP_SALLOC(s)
714 #define MPFR_TMP_FREE(x) TMP_FREE
715 #endif
716 
717 /* This code is experimental: don't use it */
718 #ifdef MPFR_USE_OWN_MPFR_TMP_ALLOC
719 extern unsigned char *mpfr_stack;
720 #undef MPFR_TMP_DECL
721 #undef MPFR_TMP_MARK
722 #undef MPFR_TMP_ALLOC
723 #undef MPFR_TMP_FREE
724 #define MPFR_TMP_DECL(_x) unsigned char *(_x)
725 #define MPFR_TMP_MARK(_x) ((_x) = mpfr_stack)
726 #define MPFR_TMP_ALLOC(_s) (mpfr_stack += (_s), mpfr_stack - (_s))
727 #define MPFR_TMP_FREE(_x) (mpfr_stack = (_x))
728 #endif
729 
730 /* temporary allocate 1 limb at xp, and initialize mpfr variable x */
731 /* The temporary var doesn't have any size field, but it doesn't matter
732  * since only functions dealing with the Heap care about it */
733 #define MPFR_TMP_INIT1(xp, x, p) \
734  ( MPFR_PREC(x) = (p), \
735  MPFR_MANT(x) = (xp), \
736  MPFR_SET_POS(x), \
737  MPFR_SET_INVALID_EXP(x))
738 
739 #define MPFR_TMP_INIT(xp, x, p, s) \
740  (xp = (mp_ptr) MPFR_TMP_ALLOC(BYTES_PER_MP_LIMB * ((size_t) s)), \
741  MPFR_TMP_INIT1(xp, x, p))
742 
743 #define MPFR_TMP_INIT_ABS(d, s) \
744  ( MPFR_PREC(d) = MPFR_PREC(s), \
745  MPFR_MANT(d) = MPFR_MANT(s), \
746  MPFR_SET_POS(d), \
747  MPFR_EXP(d) = MPFR_EXP(s))
748 
749 
750 
751 /******************************************************
752  ***************** Cache macros **********************
753  ******************************************************/
754 
755 #define mpfr_const_pi(_d,_r) mpfr_cache(_d, __gmpfr_cache_const_pi,_r)
756 #define mpfr_const_log2(_d,_r) mpfr_cache(_d, __gmpfr_cache_const_log2, _r)
757 #define mpfr_const_euler(_d,_r) mpfr_cache(_d, __gmpfr_cache_const_euler, _r)
758 #define mpfr_const_catalan(_d,_r) mpfr_cache(_d,__gmpfr_cache_const_catalan,_r)
759 
760 #define MPFR_DECL_INIT_CACHE(_cache,_func) \
761  mpfr_cache_t MPFR_THREAD_ATTR _cache = \
762  {{{{0,MPFR_SIGN_POS,0,(mp_limb_t*)0}},0,_func}}
763 
764 
765 
766 /******************************************************
767  ******************* Threshold ***********************
768  ******************************************************/
769 
770 #include <feel/feelcore/mparam.hpp>
771 
772 /******************************************************
773  ***************** Useful macros *********************
774  ******************************************************/
775 
776 /* Theses macros help the compiler to determine if a test is
777  * likely or unlikely. */
778 #if __MPFR_GNUC(3,0) || __MPFR_ICC(8,1,0)
779 # define MPFR_LIKELY(x) (__builtin_expect(!!(x),1))
780 # define MPFR_UNLIKELY(x) (__builtin_expect((x),0))
781 #else
782 # define MPFR_LIKELY(x) (x)
783 # define MPFR_UNLIKELY(x) (x)
784 #endif
785 
786 /* Ceil log 2: If GCC, uses a GCC extension, otherwise calls a function */
787 /* Warning:
788  * Needs to define MPFR_NEED_LONGLONG.
789  * Computes ceil(log2(x)) only for x integer (unsigned long)
790  * Undefined if x is 0 */
791 #if __MPFR_GNUC(2,95) || __MPFR_ICC(8,1,0)
792 # define MPFR_INT_CEIL_LOG2(x) \
793  (__extension__ ({int _b; mp_limb_t _limb = (x); \
794  MPFR_ASSERTN (_limb == (x)); \
795  count_leading_zeros (_b, _limb); \
796  (BITS_PER_MP_LIMB - _b); }))
797 #else
798 # define MPFR_INT_CEIL_LOG2(x) (__gmpfr_int_ceil_log2(x))
799 #endif
800 
801 /* Add two integers with overflow handling */
802 /* Example: MPFR_SADD_OVERFLOW (c, a, b, long, unsigned long,
803  * LONG_MIN, LONG_MAX,
804  * goto overflow, goto underflow); */
805 #define MPFR_UADD_OVERFLOW(c,a,b,ACTION_IF_OVERFLOW) \
806  do { \
807  (c) = (a) + (b); \
808  if ((c) < (a)) ACTION_IF_OVERFLOW; \
809  } while (0)
810 
811 #define MPFR_SADD_OVERFLOW(c,a,b,STYPE,UTYPE,MIN,MAX,ACTION_IF_POS_OVERFLOW,ACTION_IF_NEG_OVERFLOW) \
812  do { \
813  if ((a) >= 0 && (b) >= 0) { \
814  UTYPE uc,ua,ub; \
815  ua = (UTYPE) a; ub = (UTYPE) b; \
816  MPFR_UADD_OVERFLOW (uc, ua, ub, ACTION_IF_POS_OVERFLOW); \
817  if (uc > (UTYPE)(MAX)) ACTION_IF_POS_OVERFLOW; \
818  else (c) = (STYPE) uc; \
819  } else if ((a) < 0 && (b) < 0) { \
820  UTYPE uc,ua,ub; \
821  ua = -(UTYPE) a; ub = -(UTYPE) b; \
822  MPFR_UADD_OVERFLOW (uc, ua, ub, ACTION_IF_NEG_OVERFLOW); \
823  if (uc >= -(UTYPE)(MIN) || uc > (UTYPE)(MAX)) { \
824  if (uc == -(UTYPE)(MIN)) (c) = (MIN); \
825  else ACTION_IF_NEG_OVERFLOW; } \
826  else (c) = -(STYPE) uc; \
827  } else (c) = (a) + (b); \
828  } while (0)
829 
830 
831 /* Set a number to 1 (Fast) - It doesn't check if 1 is in the exponent range */
832 #define MPFR_SET_ONE(x) \
833 do { \
834  mp_size_t _size = MPFR_LIMB_SIZE(x) - 1; \
835  MPFR_SET_POS(x); \
836  MPFR_EXP(x) = 1; \
837  MPN_ZERO ( MPFR_MANT(x), _size); \
838  MPFR_MANT(x)[_size] = MPFR_LIMB_HIGHBIT; \
839 } while (0)
840 
841 /* Compute s = (-a) % BITS_PER_MP_LIMB
842  * a is unsigned! Check if it works,
843  * otherwise tries another way to compute it */
844 #define MPFR_UNSIGNED_MINUS_MODULO(s, a) \
845  do \
846  { \
847  if ((UINT_MAX % BITS_PER_MP_LIMB) == (BITS_PER_MP_LIMB-1)) \
848  (s) = (mpfr_prec_t) (-(a)) % BITS_PER_MP_LIMB; \
849  else \
850  { \
851  (s) = (a) % BITS_PER_MP_LIMB; \
852  if (s != 0) \
853  (s) = BITS_PER_MP_LIMB - (s); \
854  } \
855  MPFR_ASSERTD ((s) >= 0 && (s) < BITS_PER_MP_LIMB); \
856  } \
857  while (0)
858 
859 /* Use it only for debug reasons */
860 /* MPFR_TRACE (operation) : execute operation iff DEBUG flag is set */
861 /* MPFR_DUMP (x) : print x (a mpfr_t) on stdout */
862 #ifdef DEBUG
863 # include <stdio.h>
864 # define MPFR_TRACE(x) x
865 #else
866 # define MPFR_TRACE(x) (void) 0
867 #endif
868 #define MPFR_DUMP(x) ( printf(#x"="), mpfr_dump(x) )
869 
870 /* Test if X (positive) is a power of 2 */
871 #define IS_POW2(X) (((X) & ((X) - 1)) == 0)
872 #define NOT_POW2(X) (((X) & ((X) - 1)) != 0)
873 
874 /* Safe absolute value (to avoid possible integer overflow) */
875 /* type is the target (unsigned) type */
876 #define SAFE_ABS(type,x) ((x) >= 0 ? (type)(x) : -(type)(x))
877 
878 #define mpfr_get_d1(x) mpfr_get_d(x,__gmpfr_default_rounding_mode)
879 
880 /* Store in r the size in bits of the mpz_t z */
881 #define MPFR_MPZ_SIZEINBASE2(r, z) \
882  do { \
883  int _cnt; \
884  mp_size_t _size; \
885  MPFR_ASSERTD (mpz_sgn (z) != 0); \
886  _size = ABSIZ(z); \
887  count_leading_zeros (_cnt, PTR(z)[_size-1]); \
888  (r) = _size * BITS_PER_MP_LIMB - _cnt; \
889  } while (0)
890 
891 /* Needs <locale.h> */
892 #define MPFR_DECIMAL_POINT ((unsigned char) localeconv()->decimal_point[0])
893 
894 /******************************************************
895  ************** Save exponent macros ****************
896  ******************************************************/
897 
898 /* See README.dev for details on how to use the macros.
899  They are used to set the exponent range to the maximum
900  temporarily */
901 
902 typedef struct
903 {
904  unsigned int saved_flags;
905  mp_exp_t saved_emin;
906  mp_exp_t saved_emax;
907 } mpfr_save_expo_t;
908 
909 #define MPFR_SAVE_EXPO_DECL(x) mpfr_save_expo_t x
910 #define MPFR_SAVE_EXPO_MARK(x) \
911  ((x).saved_flags = __gmpfr_flags, \
912  (x).saved_emin = __gmpfr_emin, \
913  (x).saved_emax = __gmpfr_emax, \
914  __gmpfr_emin = MPFR_EMIN_MIN, \
915  __gmpfr_emax = MPFR_EMAX_MAX)
916 #define MPFR_SAVE_EXPO_FREE(x) \
917  (__gmpfr_flags = (x).saved_flags, \
918  __gmpfr_emin = (x).saved_emin, \
919  __gmpfr_emax = (x).saved_emax)
920 #define MPFR_SAVE_EXPO_UPDATE_FLAGS(x, flags) \
921  (x).saved_flags |= (flags)
922 
923 /* Speed up final checking */
924 #define mpfr_check_range(x,t,r) \
925  (MPFR_LIKELY (MPFR_EXP (x) >= __gmpfr_emin && MPFR_EXP (x) <= __gmpfr_emax) \
926  ? (t) : mpfr_check_range(x,t,r))
927 
928 
929 /******************************************************
930  ***************** Inline Rounding *******************
931  ******************************************************/
932 
933 /*
934  * Round Mantissa (`srcp`, `sprec`) to mpfr_t `dest` using rounding mode `rnd`
935  * assuming dest's sign is `sign`.
936  * Execute OVERFLOW_HANDLER in case of overflow when rounding (Power 2 case)
937  */
938 #define MPFR_RNDRAW(inexact, dest, srcp, sprec, rnd, sign, OVERFLOW_HANDLER)\
939  do { \
940  mp_size_t dests, srcs; \
941  mp_limb_t *destp; \
942  mp_prec_t destprec, srcprec; \
943  \
944  /* Check Trivial Case when Dest Mantissa has more bits than source */ \
945  srcprec = sprec; \
946  destprec = MPFR_PREC (dest); \
947  destp = MPFR_MANT (dest); \
948  if (MPFR_UNLIKELY (destprec >= srcprec)) \
949  { \
950  srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
951  dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \
952  MPN_COPY (destp + dests, srcp, srcs); \
953  MPN_ZERO (destp, dests); \
954  inexact = 0; \
955  } \
956  else \
957  { \
958  /* Non trivial case: rounding needed */ \
959  mp_prec_t sh; \
960  mp_limb_t *sp; \
961  mp_limb_t rb, sb, ulp; \
962  \
963  /* Compute Position and shift */ \
964  srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
965  dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
966  MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \
967  sp = srcp + srcs - dests; \
968  \
969  /* General case when prec % BITS_PER_MP_LIMB != 0 */ \
970  if (MPFR_LIKELY (sh != 0)) \
971  { \
972  mp_limb_t mask; \
973  /* Compute Rounding Bit and Sticky Bit */ \
974  mask = MPFR_LIMB_ONE << (sh-1); \
975  rb = sp[0] & mask; \
976  sb = sp[0] & (mask-1); \
977  if (MPFR_UNLIKELY (sb == 0)) \
978  { /* TODO: Improve it */ \
979  mp_limb_t *tmp; \
980  mp_size_t n; \
981  for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \
982  sb = *--tmp; \
983  } \
984  ulp = 2*mask; \
985  } \
986  else /* sh == 0 */ \
987  { \
988  MPFR_ASSERTD (dests < srcs); \
989  /* Compute Rounding Bit and Sticky Bit */ \
990  rb = sp[-1] & MPFR_LIMB_HIGHBIT; \
991  sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \
992  if (MPFR_UNLIKELY (sb == 0)) \
993  { \
994  mp_limb_t *tmp; \
995  mp_size_t n; \
996  for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \
997  sb = *--tmp; \
998  } \
999  ulp = MPFR_LIMB_ONE; \
1000  } \
1001  /* Rounding */ \
1002  if (MPFR_LIKELY (rnd == GMP_RNDN)) \
1003  { \
1004  if (rb == 0 || MPFR_UNLIKELY (sb == 0 && (sp[0] & ulp) == 0)) \
1005  { \
1006  trunc: \
1007  inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \
1008  MPN_COPY (destp, sp, dests); \
1009  destp[0] &= ~(ulp-1); \
1010  } \
1011  else \
1012  { \
1013  addoneulp: \
1014  if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \
1015  { \
1016  destp[dests-1] = MPFR_LIMB_HIGHBIT; \
1017  OVERFLOW_HANDLER; \
1018  } \
1019  destp[0] &= ~(ulp-1); \
1020  inexact = sign; \
1021  } \
1022  } \
1023  else \
1024  { /* Not Rounding to Nearest */ \
1025  if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\
1026  || MPFR_UNLIKELY ((sb | rb) == 0)) \
1027  goto trunc; \
1028  else \
1029  goto addoneulp; \
1030  } \
1031  } \
1032  } while (0)
1033 
1034 /*
1035  * Round Mantissa (`srcp`, `sprec`) to mpfr_t `dest` using rounding mode `rnd`
1036  * assuming dest's sign is `sign`.
1037  * Execute OVERFLOW_HANDLER in case of overflow when rounding (Power 2 case)
1038  * Return MPFR_EVEN_INEX in case of EVEN rounding
1039  */
1040 #define MPFR_RNDRAW_EVEN(inexact, dest, srcp, sprec, rnd, sign, OVERFLOW_HANDLER)\
1041  do { \
1042  mp_size_t dests, srcs; \
1043  mp_limb_t *destp; \
1044  mp_prec_t destprec, srcprec; \
1045  \
1046  /* Check Trivial Case when Dest Mantissa has more bits than source */ \
1047  srcprec = sprec; \
1048  destprec = MPFR_PREC (dest); \
1049  destp = MPFR_MANT (dest); \
1050  if (MPFR_UNLIKELY (destprec >= srcprec)) \
1051  { \
1052  srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
1053  dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \
1054  MPN_COPY (destp + dests, srcp, srcs); \
1055  MPN_ZERO (destp, dests); \
1056  inexact = 0; \
1057  } \
1058  else \
1059  { \
1060  /* Non trivial case: rounding needed */ \
1061  mp_prec_t sh; \
1062  mp_limb_t *sp; \
1063  mp_limb_t rb, sb, ulp; \
1064  \
1065  /* Compute Position and shift */ \
1066  srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
1067  dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \
1068  MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \
1069  sp = srcp + srcs - dests; \
1070  \
1071  /* General case when prec % BITS_PER_MP_LIMB != 0 */ \
1072  if (MPFR_LIKELY (sh != 0)) \
1073  { \
1074  mp_limb_t mask; \
1075  /* Compute Rounding Bit and Sticky Bit */ \
1076  mask = MPFR_LIMB_ONE << (sh-1); \
1077  rb = sp[0] & mask; \
1078  sb = sp[0] & (mask-1); \
1079  if (MPFR_UNLIKELY (sb == 0)) \
1080  { /* TODO: Improve it */ \
1081  mp_limb_t *tmp; \
1082  mp_size_t n; \
1083  for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \
1084  sb = *--tmp; \
1085  } \
1086  ulp = 2*mask; \
1087  } \
1088  else /* sh == 0 */ \
1089  { \
1090  MPFR_ASSERTD (dests < srcs); \
1091  /* Compute Rounding Bit and Sticky Bit */ \
1092  rb = sp[-1] & MPFR_LIMB_HIGHBIT; \
1093  sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \
1094  if (MPFR_UNLIKELY (sb == 0)) \
1095  { \
1096  mp_limb_t *tmp; \
1097  mp_size_t n; \
1098  for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \
1099  sb = *--tmp; \
1100  } \
1101  ulp = MPFR_LIMB_ONE; \
1102  } \
1103  /* Rounding */ \
1104  if (MPFR_LIKELY (rnd == GMP_RNDN)) \
1105  { \
1106  if (rb == 0) \
1107  { \
1108  trunc: \
1109  inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \
1110  trunc_doit: \
1111  MPN_COPY (destp, sp, dests); \
1112  destp[0] &= ~(ulp-1); \
1113  } \
1114  else if (MPFR_UNLIKELY (sb == 0)) \
1115  { \
1116  /* EVEN rounding */ \
1117  if ((sp[0] & ulp) == 0) \
1118  { \
1119  MPFR_ASSERTD (rb != 0); \
1120  inexact = -MPFR_EVEN_INEX*sign; \
1121  goto trunc_doit; \
1122  } \
1123  else \
1124  { \
1125  inexact = MPFR_EVEN_INEX*sign; \
1126  goto addoneulp_doit; \
1127  } \
1128  } \
1129  else \
1130  { \
1131  addoneulp: \
1132  inexact = sign; \
1133  addoneulp_doit: \
1134  if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \
1135  { \
1136  destp[dests-1] = MPFR_LIMB_HIGHBIT; \
1137  OVERFLOW_HANDLER; \
1138  } \
1139  destp[0] &= ~(ulp-1); \
1140  } \
1141  } \
1142  else \
1143  { /* Not Rounding to Nearest */ \
1144  if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\
1145  || MPFR_UNLIKELY ((sb | rb) == 0)) \
1146  goto trunc; \
1147  else \
1148  goto addoneulp; \
1149  } \
1150  } \
1151  } while (0)
1152 
1153 /* Return TRUE if b is non singular and we can round it to precision 'prec'
1154  with rounding mode 'rnd', and with error at most 'error' */
1155 #define MPFR_CAN_ROUND(b,err,prec,rnd) \
1156  (!MPFR_IS_SINGULAR (b) && mpfr_round_p (MPFR_MANT (b), MPFR_LIMB_SIZE (b), \
1157  (err), (prec) + ((rnd)==GMP_RNDN)))
1158 
1159 /* Assuming that the function as a taylor expansion which looks like:
1160  y=o(f(x)) = o(x + g(x)) with |g(x)| <=2^(EXP(x)-err)
1161  we can quickly set y to x if x is small (ie err > prec(y)+1) in most
1162  cases. It assumes that f(x) is not representable exactly as a FP number.
1163  x must not be a singular value (NAN, INF or ZERO).
1164 
1165  y is the destination (a mpfr_t), x the value to set (a mpfr_t),
1166  err the error term (a mp_exp_t), dir (an int) is the direction of
1167  the commited error (if dir = 0, it rounds towards 0, if dir=1,
1168  it rounds away from 0), rnd the rounding mode.
1169 
1170  It returns from the function a ternary value in case of success.
1171  If you want to free something, you must fill the "extra" field
1172  in consequences, otherwise put nothing in it.
1173 
1174  The test is less restrictive thant necessary, but the function
1175  will finish the check itself.
1176 */
1177 #define MPFR_FAST_COMPUTE_IF_SMALL_INPUT(y,x,err,dir,rnd,extra) \
1178  do { \
1179  mp_exp_t _err = (err); \
1180  if (MPFR_UNLIKELY (_err > 0 \
1181  && (mpfr_uexp_t) _err > MPFR_PREC (y) + 1)) \
1182  { \
1183  int _inexact = mpfr_round_near_x ((y),(x),(err),(dir),(rnd)); \
1184  if (_inexact != 0) \
1185  { \
1186  extra; \
1187  return _inexact; \
1188  } \
1189  } \
1190  } while (0)
1191 
1192 /******************************************************
1193  *************** Ziv Loop Macro *********************
1194  ******************************************************/
1195 
1196 #ifndef MPFR_USE_LOGGING
1197 
1198 #define MPFR_ZIV_DECL(_x) mp_prec_t _x
1199 #define MPFR_ZIV_INIT(_x, _p) (_x) = BITS_PER_MP_LIMB
1200 #define MPFR_ZIV_NEXT(_x, _p) ((_p) += (_x), (_x) = (_p)/2)
1201 #define MPFR_ZIV_FREE(x)
1202 
1203 #else
1204 /* Use LOGGING */
1205 #define MPFR_ZIV_DECL(_x) \
1206  mp_prec_t _x; \
1207  int _x ## _cpt = 1; \
1208  static unsigned long _x ## _loop = 0, _x ## _bad = 0; \
1209  static const char *_x ## _fname = __func__; \
1210  auto void __attribute__ ((destructor)) x ## _f (void); \
1211  void __attribute__ ((destructor)) x ## _f (void) { \
1212  if (_x ## _loop != 0 && MPFR_LOG_STAT_F&mpfr_log_type) \
1213  fprintf (mpfr_log_file, \
1214  "%s: Ziv failed %2.2f%% (%lu bad cases / %lu calls)\n", _x ## _fname, \
1215  (double) 100.0 * _x ## _bad / _x ## _loop, _x ## _bad, _x ## _loop ); }
1216 
1217 #define MPFR_ZIV_INIT(_x, _p) ((_x) = BITS_PER_MP_LIMB, _x ## _loop ++); \
1218  if (MPFR_LOG_BADCASE_F&mpfr_log_type && mpfr_log_current<=mpfr_log_level) \
1219  fprintf (mpfr_log_file, "%s:ZIV 1st prec=%lu\n", __func__, \
1220  (unsigned long) (_p))
1221 
1222 #define MPFR_ZIV_NEXT(_x, _p) \
1223  ((_p)+=(_x),(_x)=(_p)/2, _x ## _bad += (_x ## _cpt == 1), _x ## _cpt ++); \
1224  if (MPFR_LOG_BADCASE_F&mpfr_log_type && mpfr_log_current<=mpfr_log_level) \
1225  fprintf (mpfr_log_file, "%s:ZIV new prec=%lu\n", __func__, \
1226  (unsigned long) (_p))
1227 
1228 #define MPFR_ZIV_FREE(_x) \
1229  if (MPFR_LOG_BADCASE_F&mpfr_log_type && _x##_cpt>1 \
1230  && mpfr_log_current<=mpfr_log_level) \
1231  fprintf (mpfr_log_file, "%s:ZIV %d loops\n", __func__, _x ## _cpt)
1232 
1233 #endif
1234 
1235 
1236 /******************************************************
1237  *************** Logging Macros *********************
1238  ******************************************************/
1239 
1240 /* The different kind of LOG */
1241 #define MPFR_LOG_INPUT_F 1
1242 #define MPFR_LOG_OUTPUT_F 2
1243 #define MPFR_LOG_INTERNAL_F 4
1244 #define MPFR_LOG_TIME_F 8
1245 #define MPFR_LOG_BADCASE_F 16
1246 #define MPFR_LOG_MSG_F 32
1247 #define MPFR_LOG_STAT_F 64
1248 
1249 #ifdef MPFR_USE_LOGGING
1250 
1251 # include <stdio.h>
1252 
1253 /* Check if we can support this feature */
1254 # ifdef MPFR_USE_THREAD_SAFE
1255 # error "Enable either `Logging' or `thread-safe', not both"
1256 # endif
1257 # if !__MPFR_GNUC(3,0)
1258 # error "Logging not supported (GCC >= 3.0)"
1259 # endif
1260 
1261 #if defined (__cplusplus)
1262 extern "C" {
1263 #endif
1264 
1265  __MPFR_DECLSPEC extern FILE *mpfr_log_file;
1266  __MPFR_DECLSPEC extern int mpfr_log_type;
1267  __MPFR_DECLSPEC extern int mpfr_log_level;
1268  __MPFR_DECLSPEC extern int mpfr_log_current;
1269  __MPFR_DECLSPEC extern int mpfr_log_base;
1270  __MPFR_DECLSPEC extern mp_prec_t mpfr_log_prec;
1271 
1272 #if defined (__cplusplus)
1273 }
1274 #endif
1275 
1276 #define MPFR_LOG_VAR(x) \
1277  if((MPFR_LOG_INTERNAL_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level))\
1278  fprintf (mpfr_log_file, "%s.%d:%s[%#R]=%R\n", __func__,__LINE__, #x, x, x);
1279 
1280 #define MPFR_LOG_MSG2(format, ...) \
1281  if ((MPFR_LOG_MSG_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \
1282  fprintf (mpfr_log_file, "%s.%d:"format, __func__, __LINE__, __VA_ARGS__);
1283 #define MPFR_LOG_MSG(x) MPFR_LOG_MSG2 x
1284 
1285 #define MPFR_LOG_BEGIN2(format, ...) \
1286  mpfr_log_current ++; \
1287  if ((MPFR_LOG_INPUT_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \
1288  fprintf (mpfr_log_file, "%s:IN "format"\n",__func__,__VA_ARGS__); \
1289  if ((MPFR_LOG_TIME_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \
1290  __gmpfr_log_time = mpfr_get_cputime ();
1291 #define MPFR_LOG_BEGIN(x) \
1292  int __gmpfr_log_time = 0; \
1293  MPFR_LOG_BEGIN2 x
1294 
1295 #define MPFR_LOG_END2(format, ...) \
1296  if ((MPFR_LOG_TIME_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \
1297  fprintf (mpfr_log_file, "%s:TIM %dms\n", __mpfr_log_fname, \
1298  mpfr_get_cputime () - __gmpfr_log_time); \
1299  if ((MPFR_LOG_OUTPUT_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \
1300  fprintf (mpfr_log_file, "%s:OUT "format"\n",__mpfr_log_fname,__VA_ARGS__);\
1301  mpfr_log_current --;
1302 #define MPFR_LOG_END(x) \
1303  static const char *__mpfr_log_fname = __func__; \
1304  MPFR_LOG_END2 x
1305 
1306 #define MPFR_LOG_FUNC(begin,end) \
1307  static const char *__mpfr_log_fname = __func__; \
1308  auto void __mpfr_log_cleanup (int *time); \
1309  void __mpfr_log_cleanup (int *time) { \
1310  int __gmpfr_log_time = *time; \
1311  MPFR_LOG_END2 end; } \
1312  int __gmpfr_log_time __attribute__ ((cleanup (__mpfr_log_cleanup))); \
1313  __gmpfr_log_time = 0; \
1314  MPFR_LOG_BEGIN2 begin
1315 
1316 #else /* MPFR_USE_LOGGING */
1317 
1318 /* Define void macro for logging */
1319 
1320 #define MPFR_LOG_VAR(x)
1321 #define MPFR_LOG_BEGIN(x)
1322 #define MPFR_LOG_END(x)
1323 #define MPFR_LOG_MSG(x)
1324 #define MPFR_LOG_FUNC(x,y)
1325 
1326 #endif /* MPFR_USE_LOGGING */
1327 
1328 
1329 /**************************************************************
1330  ************ Group Initialize Functions Macros *************
1331  **************************************************************/
1332 
1333 #ifndef MPFR_GROUP_STATIC_SIZE
1334 # define MPFR_GROUP_STATIC_SIZE 16
1335 #endif
1336 
1337 struct mpfr_group_t
1338 {
1339  size_t alloc;
1340  mp_limb_t *mant;
1341  mp_limb_t tab[MPFR_GROUP_STATIC_SIZE];
1342 };
1343 
1344 #define MPFR_GROUP_DECL(g) struct mpfr_group_t g
1345 #define MPFR_GROUP_CLEAR(g) do { \
1346  if (MPFR_UNLIKELY ((g).alloc != 0)) { \
1347  MPFR_ASSERTD ((g).mant != (g).tab); \
1348  (*__gmp_free_func)((g).mant, (g).alloc); \
1349  }} while (0)
1350 
1351 #define MPFR_GROUP_INIT_TEMPLATE(g, prec, num, handler) do { \
1352  mp_prec_t _prec = (prec); \
1353  mp_size_t _size; \
1354  MPFR_ASSERTD (_prec >= MPFR_PREC_MIN); \
1355  if (MPFR_UNLIKELY (_prec > MPFR_PREC_MAX)) mpfr_abort_prec_max(); \
1356  _size = (mp_prec_t)(_prec +BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB;\
1357  if (MPFR_UNLIKELY (_size*(num) > MPFR_GROUP_STATIC_SIZE)) { \
1358  (g).alloc = (num)*_size*sizeof (mp_limb_t); \
1359  (g).mant = (*__gmp_allocate_func) ((g).alloc); \
1360  } else { \
1361  (g).alloc = 0; \
1362  (g).mant = (g).tab; \
1363  } \
1364  handler; \
1365  } while (0)
1366 #define MPFR_GROUP_TINIT(g, n, x) MPFR_TMP_INIT1 ((g).mant+_size*(n), x, _prec)
1367 
1368 #define MPFR_GROUP_INIT_1(g, prec, x) \
1369  MPFR_GROUP_INIT_TEMPLATE(g, prec, 1, MPFR_GROUP_TINIT(g, 0, x))
1370 #define MPFR_GROUP_INIT_2(g, prec, x, y) \
1371  MPFR_GROUP_INIT_TEMPLATE(g, prec, 2, \
1372  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y))
1373 #define MPFR_GROUP_INIT_3(g, prec, x, y, z) \
1374  MPFR_GROUP_INIT_TEMPLATE(g, prec, 3, \
1375  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1376  MPFR_GROUP_TINIT(g, 2, z))
1377 #define MPFR_GROUP_INIT_4(g, prec, x, y, z, t) \
1378  MPFR_GROUP_INIT_TEMPLATE(g, prec, 4, \
1379  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1380  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t))
1381 #define MPFR_GROUP_INIT_5(g, prec, x, y, z, t, a) \
1382  MPFR_GROUP_INIT_TEMPLATE(g, prec, 5, \
1383  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1384  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t); \
1385  MPFR_GROUP_TINIT(g, 4, a))
1386 #define MPFR_GROUP_INIT_6(g, prec, x, y, z, t, a, b) \
1387  MPFR_GROUP_INIT_TEMPLATE(g, prec, 6, \
1388  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1389  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t); \
1390  MPFR_GROUP_TINIT(g, 4, a);MPFR_GROUP_TINIT(g, 5, b))
1391 
1392 #define MPFR_GROUP_REPREC_TEMPLATE(g, prec, num, handler) do { \
1393  mp_prec_t _prec = (prec); \
1394  size_t _oalloc = (g).alloc; \
1395  mp_size_t _size; \
1396  MPFR_ASSERTD (_prec >= MPFR_PREC_MIN); \
1397  if (MPFR_UNLIKELY (_prec > MPFR_PREC_MAX)) mpfr_abort_prec_max(); \
1398  _size = (mp_prec_t)(_prec +BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB;\
1399  (g).alloc = (num)*_size*sizeof(mp_limb_t); \
1400  if (MPFR_LIKELY (_oalloc == 0)) \
1401  (g).mant = (*__gmp_allocate_func) ((g).alloc); \
1402  else \
1403  (g).mant = (*__gmp_reallocate_func)((g).mant,_oalloc,(g).alloc);\
1404  handler; \
1405 } while (0)
1406 
1407 
1408 #define MPFR_GROUP_REPREC_1(g, prec, x) \
1409  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 1, MPFR_GROUP_TINIT(g, 0, x))
1410 #define MPFR_GROUP_REPREC_2(g, prec, x, y) \
1411  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 2, \
1412  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y))
1413 #define MPFR_GROUP_REPREC_3(g, prec, x, y, z) \
1414  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 3, \
1415  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1416  MPFR_GROUP_TINIT(g, 2, z))
1417 #define MPFR_GROUP_REPREC_4(g, prec, x, y, z, t) \
1418  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 4, \
1419  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1420  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t))
1421 #define MPFR_GROUP_REPREC_5(g, prec, x, y, z, t, a) \
1422  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 5, \
1423  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1424  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t); \
1425  MPFR_GROUP_TINIT(g, 4, a))
1426 #define MPFR_GROUP_REPREC_6(g, prec, x, y, z, t, a, b) \
1427  MPFR_GROUP_REPREC_TEMPLATE(g, prec, 6, \
1428  MPFR_GROUP_TINIT(g, 0, x);MPFR_GROUP_TINIT(g, 1, y); \
1429  MPFR_GROUP_TINIT(g, 2, z);MPFR_GROUP_TINIT(g, 3, t); \
1430  MPFR_GROUP_TINIT(g, 4, a);MPFR_GROUP_TINIT(g, 5, b))
1431 
1432 
1433 /******************************************************
1434  *************** Internal Functions *****************
1435  ******************************************************/
1436 
1437 #if defined (__cplusplus)
1438 extern "C" {
1439 #endif
1440 
1441  __MPFR_DECLSPEC int mpfr_underflow _MPFR_PROTO ( ( mpfr_ptr, mp_rnd_t, int ) );
1442  __MPFR_DECLSPEC int mpfr_overflow _MPFR_PROTO ( ( mpfr_ptr, mp_rnd_t, int ) );
1443 
1444  __MPFR_DECLSPEC int mpfr_add1 _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,
1445  mpfr_srcptr, mp_rnd_t ) );
1446  __MPFR_DECLSPEC int mpfr_sub1 _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,
1447  mpfr_srcptr, mp_rnd_t ) );
1448  __MPFR_DECLSPEC int mpfr_add1sp _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,
1449  mpfr_srcptr, mp_rnd_t ) );
1450  __MPFR_DECLSPEC int mpfr_sub1sp _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,
1451  mpfr_srcptr, mp_rnd_t ) );
1452  __MPFR_DECLSPEC int mpfr_can_round_raw _MPFR_PROTO ( ( const mp_limb_t *,
1453  mp_size_t, int, mp_exp_t, mp_rnd_t, mp_rnd_t, mp_prec_t ) );
1454 
1455  __MPFR_DECLSPEC int mpfr_cmp2 _MPFR_PROTO ( ( mpfr_srcptr, mpfr_srcptr,
1456  mp_prec_t * ) );
1457 
1458  __MPFR_DECLSPEC long __gmpfr_ceil_log2 _MPFR_PROTO ( ( double ) );
1459  __MPFR_DECLSPEC long __gmpfr_floor_log2 _MPFR_PROTO ( ( double ) );
1460  __MPFR_DECLSPEC double __gmpfr_ceil_exp2 _MPFR_PROTO ( ( double ) );
1461  __MPFR_DECLSPEC unsigned long __gmpfr_isqrt _MPFR_PROTO ( ( unsigned long ) );
1462  __MPFR_DECLSPEC unsigned long __gmpfr_cuberoot _MPFR_PROTO ( ( unsigned long ) );
1463  __MPFR_DECLSPEC int __gmpfr_int_ceil_log2 _MPFR_PROTO ( ( unsigned long ) );
1464 
1465  __MPFR_DECLSPEC int mpfr_exp_2 _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,mp_rnd_t ) );
1466  __MPFR_DECLSPEC int mpfr_exp_3 _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,mp_rnd_t ) );
1467  __MPFR_DECLSPEC int mpfr_powerof2_raw _MPFR_PROTO ( ( mpfr_srcptr ) );
1468 
1469  __MPFR_DECLSPEC void mpfr_setmax _MPFR_PROTO ( ( mpfr_ptr, mp_exp_t ) );
1470  __MPFR_DECLSPEC void mpfr_setmin _MPFR_PROTO ( ( mpfr_ptr, mp_exp_t ) );
1471 
1472  __MPFR_DECLSPEC long mpfr_mpn_exp _MPFR_PROTO ( ( mp_limb_t *, mp_exp_t *, int,
1473  mp_exp_t, size_t ) );
1474 
1475 #ifdef _MPFR_H_FEELPP_HAS_FILE
1476  __MPFR_DECLSPEC void mpfr_fprint_binary _MPFR_PROTO ( ( FILE *, mpfr_srcptr ) );
1477 #endif
1478  __MPFR_DECLSPEC void mpfr_print_binary _MPFR_PROTO ( ( mpfr_srcptr ) );
1479  __MPFR_DECLSPEC void mpfr_print_mant_binary _MPFR_PROTO ( ( const char*,
1480  const mp_limb_t*, mp_prec_t ) );
1481  __MPFR_DECLSPEC void mpfr_set_str_binary _MPFR_PROTO( ( mpfr_ptr, const char* ) );
1482 
1483  __MPFR_DECLSPEC int mpfr_round_raw _MPFR_PROTO ( ( mp_limb_t *,
1484  const mp_limb_t *, mp_prec_t, int, mp_prec_t, mp_rnd_t, int * ) );
1485  __MPFR_DECLSPEC int mpfr_round_raw_2 _MPFR_PROTO ( ( const mp_limb_t *,
1486  mp_prec_t, int, mp_prec_t, mp_rnd_t ) );
1487  __MPFR_DECLSPEC int mpfr_round_raw_3 _MPFR_PROTO ( ( const mp_limb_t *,
1488  mp_prec_t, int, mp_prec_t, mp_rnd_t, int * ) );
1489  __MPFR_DECLSPEC int mpfr_round_raw_4 _MPFR_PROTO ( ( mp_limb_t *,
1490  const mp_limb_t *, mp_prec_t, int, mp_prec_t, mp_rnd_t ) );
1491 
1492 #define mpfr_round_raw2(xp, xn, neg, r, prec) \
1493  mpfr_round_raw_2((xp),(xn)*BITS_PER_MP_LIMB,(neg),(prec),(r))
1494 
1495  __MPFR_DECLSPEC int mpfr_check _MPFR_PROTO ( ( mpfr_srcptr ) );
1496 
1497  __MPFR_DECLSPEC int mpfr_sum_sort _MPFR_PROTO ( ( mpfr_srcptr *const,
1498  unsigned long, mpfr_srcptr * ) );
1499 
1500  __MPFR_DECLSPEC int mpfr_get_cputime _MPFR_PROTO ( ( void ) );
1501 
1502  __MPFR_DECLSPEC void mpfr_nexttozero _MPFR_PROTO ( ( mpfr_ptr ) );
1503  __MPFR_DECLSPEC void mpfr_nexttoinf _MPFR_PROTO ( ( mpfr_ptr ) );
1504 
1505  __MPFR_DECLSPEC int mpfr_const_pi_internal _MPFR_PROTO ( ( mpfr_ptr,mp_rnd_t ) );
1506  __MPFR_DECLSPEC int mpfr_const_log2_internal _MPFR_PROTO( ( mpfr_ptr,mp_rnd_t ) );
1507  __MPFR_DECLSPEC int mpfr_const_euler_internal _MPFR_PROTO( ( mpfr_ptr, mp_rnd_t ) );
1508  __MPFR_DECLSPEC int mpfr_const_catalan_internal _MPFR_PROTO( ( mpfr_ptr, mp_rnd_t ) );
1509  __MPFR_DECLSPEC void mpfr_mulhigh_n _MPFR_PROTO ( ( mp_ptr, mp_srcptr,
1510  mp_srcptr, mp_size_t ) );
1511 
1512  __MPFR_DECLSPEC int mpfr_round_p _MPFR_PROTO ( ( mp_limb_t *, mp_size_t,
1513  mp_exp_t, mp_prec_t ) );
1514 
1515  __MPFR_DECLSPEC void mpfr_dump_mant _MPFR_PROTO ( ( const mp_limb_t *,
1516  mp_prec_t, mp_prec_t,
1517  mp_prec_t ) );
1518 
1519  __MPFR_DECLSPEC int mpfr_round_near_x _MPFR_PROTO ( ( mpfr_ptr, mpfr_srcptr,
1520  mp_exp_t, int, mp_rnd_t ) );
1521  __MPFR_DECLSPEC void mpfr_abort_prec_max _MPFR_PROTO ( ( void ) )
1522  MPFR_NORETURN_ATTR;
1523 
1524 #if defined (__cplusplus)
1525 }
1526 #endif
1527 
1528 #endif

Generated on Fri Oct 25 2013 14:24:19 for Feel++ by doxygen 1.8.4