bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gmp-bug?: linking fails on windows


From: Alex Prinsier
Subject: gmp-bug?: linking fails on windows
Date: Thu, 07 Apr 2005 01:15:09 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Hello,

I while ago I compiled the static libraries of gnump for Windows
successfully using msys with mingw. However after some formatting I have
to do this again (and now I have a chance to update to a newer version
:)). Though the program I'm writing fails to link with the library. I
made a testcase:

// main.cpp
#include <gmp.h>
#include <gmpxx.h>

int main()
{
    mpf_class mpf;

    return 0;
}

I'm using Visual Studio .net to compile and I get this:
libgmp.lib(memory.o) : warning LNK4217: locally defined symbol __iob
imported in function ___gmp_default_allocate
That's only a warning though, it 'runs'.

Then I change my testcase a little:

// main2.cpp
#include <gmp.h>
#include <gmpxx.h>
#include <string>

int main()
{
    mpf_class mpf;
    std::string str;

    mpf = str;

    return 0;
}

Output:
libgmp.lib(set_str.o) : warning LNK4217: locally defined symbol
___mb_cur_max imported in function _digit_value_in_base
libgmp.lib(set_str.o) : warning LNK4217: locally defined symbol __pctype
imported in function _digit_value_in_base
libgmp.lib(memory.o) : warning LNK4217: locally defined symbol __iob
imported in function ___gmp_default_allocate
libgmp.lib(assert.o) : warning LNK4049: locally defined symbol __iob
imported
libgmp.lib(mul_fft.o) : error LNK2001: unresolved external symbol __alloca
libgmp.lib(tdiv_qr.o) : error LNK2019: unresolved external symbol
__alloca referenced in function ___gmpn_tdiv_qr
libgmp.lib(dc_divrem_n.o) : error LNK2019: unresolved external symbol
__alloca referenced in function ___gmpn_dc_divrem_n
libgmp.lib(set_str.o) : error LNK2019: unresolved external symbol
__alloca referenced in function ___gmpf_set_str
libgmp.lib(mul.o) : error LNK2019: unresolved external symbol __alloca
referenced in function ___gmpn_sqr_n
libgmp.lib(divrem.o) : error LNK2019: unresolved external symbol
__alloca referenced in function ___gmpn_divrem
libgmp.lib(mul_n.o) : error LNK2001: unresolved external symbol __alloca
Debug/test3.exe : fatal error LNK1120: 1 unresolved externals

This is what I did to compile the gnump libraries: in msys I unpacked
the sourcecode of gnump(4.1.4) and ran this: ./configure --enable-cxx
--disable-dynamic --enable-static
Then I copied the .libs/libgmp.a and .libs/libgmpxx.a to my project
folder and told visual studio to include them when linking.

I tried creating a .lib of them with the lib program, that ships with
visual studio, though the results are exactly the same.

I attached the gmp.h and gmpxx.h too as at least one of them seams to
get autogenerated.
If there is any more information you could use please ask me.
I hope you can help me solve my problem, and potentially help alot of
other users experiencing the same problems.
And yes I have searched google all day :)

Sincerely,
Alex Prinsier

/* Definitions for GNU multiple precision functions.   -*- mode: c -*-

Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
2004 Free Software Foundation, Inc.

This file is part of the GNU MP Library.

The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.

The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */

#ifndef __GMP_H__

#if defined (__cplusplus)
#include <iosfwd>   /* for istream, ostream */
#endif


/* Instantiated by configure. */
#if ! defined (__GMP_WITHIN_CONFIGURE)
#define __GMP_BITS_PER_MP_LIMB             32
#define __GMP_HAVE_HOST_CPU_FAMILY_power   0
#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0
#define GMP_LIMB_BITS                      32
#define GMP_NAIL_BITS                      0
#endif
#define GMP_NUMB_BITS     (GMP_LIMB_BITS - GMP_NAIL_BITS)
#define GMP_NUMB_MASK     ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS)
#define GMP_NUMB_MAX      GMP_NUMB_MASK
#define GMP_NAIL_MASK     (~ GMP_NUMB_MASK)


/* The following (everything under ifndef __GNU_MP__) must be identical in
   gmp.h and mp.h to allow both to be included in an application or during
   the library build.  */
#ifndef __GNU_MP__
#define __GNU_MP__ 4

#define __need_size_t  /* tell gcc stddef.h we only want size_t */
#if defined (__cplusplus)
#include <cstddef>     /* for size_t */
#else
#include <stddef.h>    /* for size_t */
#endif
#undef __need_size_t

/* Instantiated by configure. */
#if ! defined (__GMP_WITHIN_CONFIGURE)
/* #undef _LONG_LONG_LIMB */
#define __GMP_LIBGMP_DLL  0
#endif


/* __STDC__ - some ANSI compilers define this only to 0, hence the use of
       "defined" and not "__STDC__-0".  In particular Sun workshop C 5.0
       sets __STDC__ to 0, but requires "##" for token pasting.

   _AIX - gnu ansidecl.h asserts that all known AIX compilers are ANSI but
       don't always define __STDC__.

   _mips - gnu ansidecl.h says the RISC/OS MIPS compiler is ANSI in SVR4
       mode, but doesn't define __STDC__.

   _MSC_VER - Microsoft C is ANSI, but __STDC__ is undefined unless the /Za
       option is given (in which case it's 1).

   _WIN32 - tested for by gnu ansidecl.h, no doubt on the assumption that
      all w32 compilers are ansi.  */

#if  defined (__STDC__)                                 \
  || defined (__cplusplus)                              \
  || defined (_AIX)                                     \
  || defined (__DECC)                                   \
  || (defined (__mips) && defined (_SYSTYPE_SVR4))      \
  || defined (_MSC_VER)                                 \
  || defined (_WIN32)
#define __GMP_HAVE_CONST        1
#define __GMP_HAVE_PROTOTYPES   1
#define __GMP_HAVE_TOKEN_PASTE  1
#else
#define __GMP_HAVE_CONST        0
#define __GMP_HAVE_PROTOTYPES   0
#define __GMP_HAVE_TOKEN_PASTE  0
#endif


#if __GMP_HAVE_CONST
#define __gmp_const   const
#define __gmp_signed  signed
#else
#define __gmp_const
#define __gmp_signed
#endif


/* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in
   all other circumstances.

   When compiling objects for libgmp, __GMP_DECLSPEC is an export directive,
   or when compiling for an application it's an import directive.  The two
   cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles
   (and not defined from an application).

   __GMP_DECLSPEC_XX is similarly used for libgmpxx.  __GMP_WITHIN_GMPXX
   indicates when building libgmpxx, and in that case libgmpxx functions are
   exports, but libgmp functions which might get called are imports.

   libmp.la uses __GMP_DECLSPEC, just as if it were libgmp.la.  libgmp and
   libmp don't call each other, so there's no conflict or confusion.

   Libtool DLL_EXPORT define is not used.

   There's no attempt to support GMP built both static and DLL.  Doing so
   would mean applications would have to tell us which of the two is going
   to be used when linking, and that seems very tedious and error prone if
   using GMP by hand, and equally tedious from a package since autoconf and
   automake don't give much help.

   __GMP_DECLSPEC is required on all documented global functions and
   variables, the various internals in gmp-impl.h etc can be left unadorned.
   But internals used by the test programs or speed measuring programs
   should have __GMP_DECLSPEC, and certainly constants or variables must
   have it or the wrong address will be resolved.  */

#if defined (__GNUC__)
#define __GMP_DECLSPEC_EXPORT  __declspec(__dllexport__)
#define __GMP_DECLSPEC_IMPORT  __declspec(__dllimport__)
#endif
#if defined (_MSC_VER) || defined (__BORLANDC__)
#define __GMP_DECLSPEC_EXPORT  __declspec(dllexport)
#define __GMP_DECLSPEC_IMPORT  __declspec(dllimport)
#endif
#ifdef __WATCOMC__
#define __GMP_DECLSPEC_EXPORT  __export
#define __GMP_DECLSPEC_IMPORT  __import
#endif
#ifdef __IBMC__
#define __GMP_DECLSPEC_EXPORT  _Export
#define __GMP_DECLSPEC_IMPORT  _Import
#endif

#if __GMP_LIBGMP_DLL
#if __GMP_WITHIN_GMP
/* compiling to go into a DLL libgmp */
#define __GMP_DECLSPEC  __GMP_DECLSPEC_EXPORT
#else
/* compiling to go into an application which will link to a DLL libgmp */
#define __GMP_DECLSPEC  __GMP_DECLSPEC_IMPORT
#endif
#else
/* all other cases */
#define __GMP_DECLSPEC
#endif


#ifdef __GMP_SHORT_LIMB
typedef unsigned int            mp_limb_t;
typedef int                     mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int  mp_limb_t;
typedef long long int           mp_limb_signed_t;
#else
typedef unsigned long int       mp_limb_t;
typedef long int                mp_limb_signed_t;
#endif
#endif

typedef mp_limb_t *             mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
#if defined (_CRAY) && ! defined (_CRAYMPP)
/* plain `int' is much faster (48 bits) */
#define __GMP_MP_SIZE_T_INT     1
typedef int                     mp_size_t;
typedef int                     mp_exp_t;
#else
#define __GMP_MP_SIZE_T_INT     0
typedef long int                mp_size_t;
typedef long int                mp_exp_t;
#endif

typedef struct
{
  int _mp_alloc;                /* Number of *limbs* allocated and pointed
                                   to by the _mp_d field.  */
  int _mp_size;                 /* abs(_mp_size) is the number of limbs the
                                   last field points to.  If _mp_size is
                                   negative this is a negative number.  */
  mp_limb_t *_mp_d;             /* Pointer to the limbs.  */
} __mpz_struct;
#endif /* __GNU_MP__ */

typedef __mpz_struct MP_INT;
typedef __mpz_struct mpz_t[1];

typedef struct
{
  __mpz_struct _mp_num;
  __mpz_struct _mp_den;
} __mpq_struct;

typedef __mpq_struct MP_RAT;
typedef __mpq_struct mpq_t[1];

typedef struct
{
  int _mp_prec;                 /* Max precision, in number of `mp_limb_t's.
                                   Set by mpf_init and modified by
                                   mpf_set_prec.  The area pointed to by the
                                   _mp_d field contains `prec' + 1 limbs.  */
  int _mp_size;                 /* abs(_mp_size) is the number of limbs the
                                   last field points to.  If _mp_size is
                                   negative this is a negative number.  */
  mp_exp_t _mp_exp;             /* Exponent, in the base of `mp_limb_t'.  */
  mp_limb_t *_mp_d;             /* Pointer to the limbs.  */
} __mpf_struct;

/* typedef __mpf_struct MP_FLOAT; */
typedef __mpf_struct mpf_t[1];

/* Available random number generation algorithms.  */
typedef enum
{
  GMP_RAND_ALG_DEFAULT = 0,
  GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential.  */
} gmp_randalg_t;

/* Linear congruential data struct.  */
typedef struct {
  mpz_t _mp_a;                  /* Multiplier. */
  unsigned long int _mp_c;      /* Adder. */
  mpz_t _mp_m;                  /* Modulus (valid only if m2exp == 0).  */
  unsigned long int _mp_m2exp;  /* If != 0, modulus is 2 ^ m2exp.  */
} __gmp_randata_lc;

/* Random state struct.  */
typedef struct
{
  mpz_t _mp_seed;               /* Current seed.  */
  gmp_randalg_t _mp_alg;        /* Algorithm used.  */
  union {                       /* Algorithm specific data.  */
    __gmp_randata_lc *_mp_lc;   /* Linear congruential.  */
  } _mp_algdata;
} __gmp_randstate_struct;
typedef __gmp_randstate_struct gmp_randstate_t[1];

/* Types for function declarations in gmp files.  */
/* ??? Should not pollute user name space with these ??? */
typedef __gmp_const __mpz_struct *mpz_srcptr;
typedef __mpz_struct *mpz_ptr;
typedef __gmp_const __mpf_struct *mpf_srcptr;
typedef __mpf_struct *mpf_ptr;
typedef __gmp_const __mpq_struct *mpq_srcptr;
typedef __mpq_struct *mpq_ptr;


/* This is not wanted in mp.h, so put it outside the __GNU_MP__ common
   section. */
#if __GMP_LIBGMP_DLL
#if __GMP_WITHIN_GMPXX
/* compiling to go into a DLL libgmpxx */
#define __GMP_DECLSPEC_XX  __GMP_DECLSPEC_EXPORT
#else
/* compiling to go into a application which will link to a DLL libgmpxx */
#define __GMP_DECLSPEC_XX  __GMP_DECLSPEC_IMPORT
#endif
#else
/* all other cases */
#define __GMP_DECLSPEC_XX
#endif


#if __GMP_HAVE_PROTOTYPES
#define __GMP_PROTO(x) x
#else
#define __GMP_PROTO(x) ()
#endif

#ifndef __MPN
#if __GMP_HAVE_TOKEN_PASTE
#define __MPN(x) __gmpn_##x
#else
#define __MPN(x) __gmpn_/**/x
#endif
#endif

#if defined (FILE)                                              \
  || defined (H_STDIO)                                          \
  || defined (_H_STDIO)               /* AIX */                 \
  || defined (_STDIO_H)               /* glibc, Sun, SCO */     \
  || defined (_STDIO_H_)              /* BSD, OSF */            \
  || defined (__STDIO_H)              /* Borland */             \
  || defined (__STDIO_H__)            /* IRIX */                \
  || defined (_STDIO_INCLUDED)        /* HPUX */                \
  || defined (__dj_include_stdio_h_)  /* DJGPP */               \
  || defined (_FILE_DEFINED)          /* Microsoft */          \
  || defined (__STDIO__)              /* Apple MPW MrC */       \
  || defined (_MSL_STDIO_H)           /* Metrowerks */
#define _GMP_H_HAVE_FILE 1
#endif

/* In ISO C, if a prototype involving "struct obstack *" is given without
   that structure defined, then the struct is scoped down to just the
   prototype, causing a conflict if it's subsequently defined for real.  So
   only give prototypes if we've got obstack.h.  */
#if defined (_OBSTACK_H)   /* glibc <obstack.h> */
#define _GMP_H_HAVE_OBSTACK 1
#endif

/* The prototypes for gmp_vprintf etc are provided only if va_list is
   available, via an application having included <stdarg.h> or <varargs.h>.
   Usually va_list is a typedef so can't be tested directly, but va_start is
   almost certainly a macro, so look for that.

   <stdio.h> will define some sort of va_list for vprintf and vfprintf, but
   let's not bother trying to use that since it's not standard and since
   application uses for gmp_vprintf etc will almost certainly require the
   whole <stdarg.h> or <varargs.h> anyway.  */

#ifdef va_start
#define _GMP_H_HAVE_VA_LIST 1
#endif

/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
#define __GMP_GNUC_PREREQ(maj, min) \
  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define __GMP_GNUC_PREREQ(maj, min)  0
#endif

/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes".  Basically
   it means a function does nothing but examine its arguments and memory
   (global or via arguments) to generate a return value, but changes nothing
   and has no side-effects. */
#if __GMP_GNUC_PREREQ (2,96)
#define __GMP_ATTRIBUTE_PURE   __attribute__ ((__pure__))
#else
#define __GMP_ATTRIBUTE_PURE
#endif


/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean
   to "g++ -Wold-style-cast".

   Casts in "extern inline" code within an extern "C" block don't induce
   these warnings, so __GMP_CAST only needs to be used on documented
   macros.  */

#ifdef __cplusplus
#define __GMP_CAST(type, expr)  (static_cast<type> (expr))
#else
#define __GMP_CAST(type, expr)  ((type) (expr))
#endif


/* An empty "throw ()" means the function doesn't throw any C++ exceptions,
   this can save some stack frame info in applications.

   Currently it's given only on functions which never divide-by-zero etc,
   don't allocate memory, and are expected to never need to allocate memory.
   This leaves open the possibility of a C++ throw from a future GMP
   exceptions scheme.

   mpz_set_ui etc are omitted to leave open the lazy allocation scheme
   described in doc/tasks.html.  mpz_get_d etc are omitted to leave open
   exceptions for float overflows.

   Note that __GMP_NOTHROW must be given on any inlines the same as on their
   prototypes (for g++ at least, where they're used together).  Note also
   that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like
   __GMP_ATTRIBUTE_PURE.  */

#if defined (__cplusplus)
#define __GMP_NOTHROW  throw ()
#else
#define __GMP_NOTHROW
#endif


/* PORTME: What other compilers have a useful "extern inline"?  "static
   inline" would be an acceptable substitute if the compiler (or linker)
   discards unused statics.  */

/* gcc has __inline__ in all modes, including strict ansi.  Give a prototype
   for an inline too, so as to correctly specify "dllimport" on windows, in
   case the function is called rather than inlined.  */
#ifdef __GNUC__
#define __GMP_EXTERN_INLINE      extern __inline__
#define __GMP_INLINE_PROTOTYPES  1
#endif

/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict
   ANSI mode (__STDC__ is 1 in that mode).  Inlining only actually takes
   place under -O.  Without -O "foo" seems to be emitted whether it's used
   or not, which is wasteful.  "extern inline foo()" isn't useful, the
   "extern" is apparently ignored, so foo is inlined if possible but also
   emitted as a global, which causes multiple definition errors when
   building a shared libgmp.  */
#ifdef __SCO_VERSION__
#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \
  && ! defined (__GMP_EXTERN_INLINE)
#define __GMP_EXTERN_INLINE  static inline
#endif
#endif

/* C++ always has "inline" and since it's a normal feature the linker should
   discard duplicate non-inlined copies, or if it doesn't then that's a
   problem for everyone, not just GMP.  */
#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE)
#define __GMP_EXTERN_INLINE  inline
#endif

/* Don't do any inlining within a configure run, since if the compiler ends
   up emitting copies of the code into the object file it can end up
   demanding the various support routines (like mpn_popcount) for linking,
   making the "alloca" test and perhaps others fail.  And on hppa ia64 a
   pre-release gcc 3.2 was seen not respecting the "extern" in "extern
   __inline__", triggering this problem too.  */
#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE
#undef __GMP_EXTERN_INLINE
#endif

/* By default, don't give a prototype when there's going to be an inline
   version.  Note in particular that Cray C++ objects to the combination of
   prototype and inline.  */
#ifdef __GMP_EXTERN_INLINE
#ifndef __GMP_INLINE_PROTOTYPES
#define __GMP_INLINE_PROTOTYPES  0
#endif
#else
#define __GMP_INLINE_PROTOTYPES  1
#endif


#define __GMP_ABS(x)   ((x) >= 0 ? (x) : -(x))
#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i))

#define __GMP_UINT_MAX   (~ (unsigned) 0)
#define __GMP_ULONG_MAX  (~ (unsigned long) 0)
#define __GMP_USHRT_MAX  ((unsigned short) ~0)


/* Allow direct user access to numerator and denominator of a mpq_t object.  */
#define mpq_numref(Q) (&((Q)->_mp_num))
#define mpq_denref(Q) (&((Q)->_mp_den))


#if defined (__cplusplus)
extern "C" {
#endif

#define mp_set_memory_functions __gmp_set_memory_functions
__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (size_t),
                                      void *(*) (void *, size_t, size_t),
                                      void (*) (void *, size_t))) __GMP_NOTHROW;

#define mp_bits_per_limb __gmp_bits_per_limb
__GMP_DECLSPEC extern __gmp_const int mp_bits_per_limb;

#define gmp_errno __gmp_errno
__GMP_DECLSPEC extern int gmp_errno;

#define gmp_version __gmp_version
__GMP_DECLSPEC extern __gmp_const char * __gmp_const gmp_version;

/* The following for internal use only.
   Enhancement: __gmp_allocate_func could have "__attribute__ ((malloc))",
   but current gcc (3.0) doesn't seem to support that.  */
__GMP_DECLSPEC extern void * (*__gmp_allocate_func) __GMP_PROTO ((size_t));
__GMP_DECLSPEC extern void * (*__gmp_reallocate_func) __GMP_PROTO ((void *, 
size_t, size_t));
__GMP_DECLSPEC extern void   (*__gmp_free_func) __GMP_PROTO ((void *, size_t));


/**************** Random number routines.  ****************/

/* obsolete */
#define gmp_randinit __gmp_randinit
__GMP_DECLSPEC void gmp_randinit __GMP_PROTO ((gmp_randstate_t, gmp_randalg_t, 
...));

#define gmp_randinit_default __gmp_randinit_default
__GMP_DECLSPEC void gmp_randinit_default __GMP_PROTO ((gmp_randstate_t));

#define gmp_randinit_lc __gmp_randinit_lc
__GMP_DECLSPEC void gmp_randinit_lc __GMP_PROTO ((gmp_randstate_t,
                              mpz_srcptr, unsigned long int, mpz_srcptr));

#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp
__GMP_DECLSPEC void gmp_randinit_lc_2exp __GMP_PROTO ((gmp_randstate_t,
                                   mpz_srcptr, unsigned long int,
                                   unsigned long int));

#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size
__GMP_DECLSPEC int gmp_randinit_lc_2exp_size __GMP_PROTO ((gmp_randstate_t, 
unsigned long));

#define gmp_randseed __gmp_randseed
__GMP_DECLSPEC void gmp_randseed __GMP_PROTO ((gmp_randstate_t, mpz_srcptr));

#define gmp_randseed_ui __gmp_randseed_ui
__GMP_DECLSPEC void gmp_randseed_ui __GMP_PROTO ((gmp_randstate_t, unsigned 
long int));

#define gmp_randclear __gmp_randclear
__GMP_DECLSPEC void gmp_randclear __GMP_PROTO ((gmp_randstate_t));


/**************** Formatted output routines.  ****************/

#define gmp_asprintf __gmp_asprintf
__GMP_DECLSPEC int gmp_asprintf __GMP_PROTO ((char **, const char *, ...));

#define gmp_fprintf __gmp_fprintf
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((FILE *, const char *, ...));
#endif

#define gmp_obstack_printf __gmp_obstack_printf
#if defined (_GMP_H_HAVE_OBSTACK)
__GMP_DECLSPEC int gmp_obstack_printf __GMP_PROTO ((struct obstack *, const 
char *, ...));
#endif

#define gmp_obstack_vprintf __gmp_obstack_vprintf
#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, const 
char *, va_list));
#endif

#define gmp_printf __gmp_printf
__GMP_DECLSPEC int gmp_printf __GMP_PROTO ((const char *, ...));

#define gmp_snprintf __gmp_snprintf
__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, size_t, const char *, 
...));

#define gmp_sprintf __gmp_sprintf
__GMP_DECLSPEC int gmp_sprintf __GMP_PROTO ((char *, const char *, ...));

#define gmp_vasprintf __gmp_vasprintf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, const char *, va_list));
#endif

#define gmp_vfprintf __gmp_vfprintf
#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((FILE *, const char *, va_list));
#endif

#define gmp_vprintf __gmp_vprintf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((const char *, va_list));
#endif

#define gmp_vsnprintf __gmp_vsnprintf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, size_t, const char *, 
va_list));
#endif

#define gmp_vsprintf __gmp_vsprintf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, const char *, va_list));
#endif


/**************** Formatted input routines.  ****************/

#define gmp_fscanf __gmp_fscanf
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((FILE *, const char *, ...));
#endif

#define gmp_scanf __gmp_scanf
__GMP_DECLSPEC int gmp_scanf __GMP_PROTO ((const char *, ...));

#define gmp_sscanf __gmp_sscanf
__GMP_DECLSPEC int gmp_sscanf __GMP_PROTO ((const char *, const char *, ...));

#define gmp_vfscanf __gmp_vfscanf
#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((FILE *, const char *, va_list));
#endif

#define gmp_vscanf __gmp_vscanf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((const char *, va_list));
#endif

#define gmp_vsscanf __gmp_vsscanf
#if defined (_GMP_H_HAVE_VA_LIST)
__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((const char *, const char *, 
va_list));
#endif


/**************** Integer (i.e. Z) routines.  ****************/

#define _mpz_realloc __gmpz_realloc
#define mpz_realloc __gmpz_realloc
__GMP_DECLSPEC void *_mpz_realloc __GMP_PROTO ((mpz_ptr, mp_size_t));

#define mpz_abs __gmpz_abs
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs)
__GMP_DECLSPEC void mpz_abs __GMP_PROTO ((mpz_ptr, mpz_srcptr));
#endif

#define mpz_add __gmpz_add
__GMP_DECLSPEC void mpz_add __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_add_ui __gmpz_add_ui
__GMP_DECLSPEC void mpz_add_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_addmul __gmpz_addmul
__GMP_DECLSPEC void mpz_addmul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_addmul_ui __gmpz_addmul_ui
__GMP_DECLSPEC void mpz_addmul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_and __gmpz_and
__GMP_DECLSPEC void mpz_and __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_array_init __gmpz_array_init
__GMP_DECLSPEC void mpz_array_init __GMP_PROTO ((mpz_ptr, mp_size_t, 
mp_size_t));

#define mpz_bin_ui __gmpz_bin_ui
__GMP_DECLSPEC void mpz_bin_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_bin_uiui __gmpz_bin_uiui
__GMP_DECLSPEC void mpz_bin_uiui __GMP_PROTO ((mpz_ptr, unsigned long int, 
unsigned long int));

#define mpz_cdiv_q __gmpz_cdiv_q
__GMP_DECLSPEC void mpz_cdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp
__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long));

#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui
__GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_cdiv_qr __gmpz_cdiv_qr
__GMP_DECLSPEC void mpz_cdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui
__GMP_DECLSPEC unsigned long int mpz_cdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_cdiv_r __gmpz_cdiv_r
__GMP_DECLSPEC void mpz_cdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp
__GMP_DECLSPEC void mpz_cdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long));

#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui
__GMP_DECLSPEC unsigned long int mpz_cdiv_r_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_cdiv_ui __gmpz_cdiv_ui
__GMP_DECLSPEC unsigned long int mpz_cdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned 
long int)) __GMP_ATTRIBUTE_PURE;

#define mpz_clear __gmpz_clear
__GMP_DECLSPEC void mpz_clear __GMP_PROTO ((mpz_ptr));

#define mpz_clrbit __gmpz_clrbit
__GMP_DECLSPEC void mpz_clrbit __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_cmp __gmpz_cmp
__GMP_DECLSPEC int mpz_cmp __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpz_cmp_d __gmpz_cmp_d
__GMP_DECLSPEC int mpz_cmp_d __GMP_PROTO ((mpz_srcptr, double)) 
__GMP_ATTRIBUTE_PURE;

#define _mpz_cmp_si __gmpz_cmp_si
__GMP_DECLSPEC int _mpz_cmp_si __GMP_PROTO ((mpz_srcptr, signed long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define _mpz_cmp_ui __gmpz_cmp_ui
__GMP_DECLSPEC int _mpz_cmp_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_cmpabs __gmpz_cmpabs
__GMP_DECLSPEC int mpz_cmpabs __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_cmpabs_d __gmpz_cmpabs_d
__GMP_DECLSPEC int mpz_cmpabs_d __GMP_PROTO ((mpz_srcptr, double)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_cmpabs_ui __gmpz_cmpabs_ui
__GMP_DECLSPEC int mpz_cmpabs_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_com __gmpz_com
__GMP_DECLSPEC void mpz_com __GMP_PROTO ((mpz_ptr, mpz_srcptr));

#define mpz_congruent_p __gmpz_congruent_p
__GMP_DECLSPEC int mpz_congruent_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, 
mpz_srcptr)) __GMP_ATTRIBUTE_PURE;

#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p
__GMP_DECLSPEC int mpz_congruent_2exp_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, 
unsigned long)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_congruent_ui_p __gmpz_congruent_ui_p
__GMP_DECLSPEC int mpz_congruent_ui_p __GMP_PROTO ((mpz_srcptr, unsigned long, 
unsigned long)) __GMP_ATTRIBUTE_PURE;

#define mpz_divexact __gmpz_divexact
__GMP_DECLSPEC void mpz_divexact __GMP_PROTO ((mpz_ptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_divexact_ui __gmpz_divexact_ui
__GMP_DECLSPEC void mpz_divexact_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long));

#define mpz_divisible_p __gmpz_divisible_p
__GMP_DECLSPEC int mpz_divisible_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_divisible_ui_p __gmpz_divisible_ui_p
__GMP_DECLSPEC int mpz_divisible_ui_p __GMP_PROTO ((mpz_srcptr, unsigned long)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p
__GMP_DECLSPEC int mpz_divisible_2exp_p __GMP_PROTO ((mpz_srcptr, unsigned 
long)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_dump __gmpz_dump
__GMP_DECLSPEC void mpz_dump __GMP_PROTO ((mpz_srcptr));

#define mpz_export __gmpz_export
__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, 
int, size_t, mpz_srcptr));

#define mpz_fac_ui __gmpz_fac_ui
__GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_fdiv_q __gmpz_fdiv_q
__GMP_DECLSPEC void mpz_fdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp
__GMP_DECLSPEC void mpz_fdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui
__GMP_DECLSPEC unsigned long int mpz_fdiv_q_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_fdiv_qr __gmpz_fdiv_qr
__GMP_DECLSPEC void mpz_fdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui
__GMP_DECLSPEC unsigned long int mpz_fdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_fdiv_r __gmpz_fdiv_r
__GMP_DECLSPEC void mpz_fdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp
__GMP_DECLSPEC void mpz_fdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui
__GMP_DECLSPEC unsigned long int mpz_fdiv_r_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_fdiv_ui __gmpz_fdiv_ui
__GMP_DECLSPEC unsigned long int mpz_fdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned 
long int)) __GMP_ATTRIBUTE_PURE;

#define mpz_fib_ui __gmpz_fib_ui
__GMP_DECLSPEC void mpz_fib_ui __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_fib2_ui __gmpz_fib2_ui
__GMP_DECLSPEC void mpz_fib2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, unsigned long 
int));

#define mpz_fits_sint_p __gmpz_fits_sint_p
__GMP_DECLSPEC int mpz_fits_sint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpz_fits_slong_p __gmpz_fits_slong_p
__GMP_DECLSPEC int mpz_fits_slong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpz_fits_sshort_p __gmpz_fits_sshort_p
__GMP_DECLSPEC int mpz_fits_sshort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpz_fits_uint_p __gmpz_fits_uint_p
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p)
__GMP_DECLSPEC int mpz_fits_uint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;
#endif

#define mpz_fits_ulong_p __gmpz_fits_ulong_p
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p)
__GMP_DECLSPEC int mpz_fits_ulong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;
#endif

#define mpz_fits_ushort_p __gmpz_fits_ushort_p
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p)
__GMP_DECLSPEC int mpz_fits_ushort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;
#endif

#define mpz_gcd __gmpz_gcd
__GMP_DECLSPEC void mpz_gcd __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_gcd_ui __gmpz_gcd_ui
__GMP_DECLSPEC unsigned long int mpz_gcd_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, 
unsigned long int));

#define mpz_gcdext __gmpz_gcdext
__GMP_DECLSPEC void mpz_gcdext __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, 
mpz_srcptr, mpz_srcptr));

#define mpz_get_d __gmpz_get_d
__GMP_DECLSPEC double mpz_get_d __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE;

#define mpz_get_d_2exp __gmpz_get_d_2exp
__GMP_DECLSPEC double mpz_get_d_2exp __GMP_PROTO ((signed long int *, 
mpz_srcptr));

#define mpz_get_si __gmpz_get_si
__GMP_DECLSPEC /* signed */ long int mpz_get_si __GMP_PROTO ((mpz_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_get_str __gmpz_get_str
__GMP_DECLSPEC char *mpz_get_str __GMP_PROTO ((char *, int, mpz_srcptr));

#define mpz_get_ui __gmpz_get_ui
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui)
__GMP_DECLSPEC unsigned long int mpz_get_ui __GMP_PROTO ((mpz_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
#endif

#define mpz_getlimbn __gmpz_getlimbn
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn)
__GMP_DECLSPEC mp_limb_t mpz_getlimbn __GMP_PROTO ((mpz_srcptr, mp_size_t)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
#endif

#define mpz_hamdist __gmpz_hamdist
__GMP_DECLSPEC unsigned long int mpz_hamdist __GMP_PROTO ((mpz_srcptr, 
mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_import __gmpz_import
__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, size_t, int, size_t, int, 
size_t, const void *));

#define mpz_init __gmpz_init
__GMP_DECLSPEC void mpz_init __GMP_PROTO ((mpz_ptr));

#define mpz_init2 __gmpz_init2
__GMP_DECLSPEC void mpz_init2 __GMP_PROTO ((mpz_ptr, unsigned long));

#define mpz_init_set __gmpz_init_set
__GMP_DECLSPEC void mpz_init_set __GMP_PROTO ((mpz_ptr, mpz_srcptr));

#define mpz_init_set_d __gmpz_init_set_d
__GMP_DECLSPEC void mpz_init_set_d __GMP_PROTO ((mpz_ptr, double));

#define mpz_init_set_si __gmpz_init_set_si
__GMP_DECLSPEC void mpz_init_set_si __GMP_PROTO ((mpz_ptr, signed long int));

#define mpz_init_set_str __gmpz_init_set_str
__GMP_DECLSPEC int mpz_init_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, 
int));

#define mpz_init_set_ui __gmpz_init_set_ui
__GMP_DECLSPEC void mpz_init_set_ui __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_inp_raw __gmpz_inp_raw
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, FILE *));
#endif

#define mpz_inp_str __gmpz_inp_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, FILE *, int));
#endif

#define mpz_invert __gmpz_invert
__GMP_DECLSPEC int mpz_invert __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_ior __gmpz_ior
__GMP_DECLSPEC void mpz_ior __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_jacobi __gmpz_jacobi
__GMP_DECLSPEC int mpz_jacobi __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_kronecker mpz_jacobi  /* alias */

#define mpz_kronecker_si __gmpz_kronecker_si
__GMP_DECLSPEC int mpz_kronecker_si __GMP_PROTO ((mpz_srcptr, long)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_kronecker_ui __gmpz_kronecker_ui
__GMP_DECLSPEC int mpz_kronecker_ui __GMP_PROTO ((mpz_srcptr, unsigned long)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_si_kronecker __gmpz_si_kronecker
__GMP_DECLSPEC int mpz_si_kronecker __GMP_PROTO ((long, mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_ui_kronecker __gmpz_ui_kronecker
__GMP_DECLSPEC int mpz_ui_kronecker __GMP_PROTO ((unsigned long, mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_lcm __gmpz_lcm
__GMP_DECLSPEC void mpz_lcm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_lcm_ui __gmpz_lcm_ui
__GMP_DECLSPEC void mpz_lcm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long));

#define mpz_legendre mpz_jacobi  /* alias */

#define mpz_lucnum_ui __gmpz_lucnum_ui
__GMP_DECLSPEC void mpz_lucnum_ui __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_lucnum2_ui __gmpz_lucnum2_ui
__GMP_DECLSPEC void mpz_lucnum2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, unsigned 
long int));

#define mpz_millerrabin __gmpz_millerrabin
__GMP_DECLSPEC int mpz_millerrabin __GMP_PROTO ((mpz_srcptr, int)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_mod __gmpz_mod
__GMP_DECLSPEC void mpz_mod __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_mul __gmpz_mul
__GMP_DECLSPEC void mpz_mul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_mul_2exp __gmpz_mul_2exp
__GMP_DECLSPEC void mpz_mul_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_mul_si __gmpz_mul_si
__GMP_DECLSPEC void mpz_mul_si __GMP_PROTO ((mpz_ptr, mpz_srcptr, long int));

#define mpz_mul_ui __gmpz_mul_ui
__GMP_DECLSPEC void mpz_mul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_neg __gmpz_neg
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg)
__GMP_DECLSPEC void mpz_neg __GMP_PROTO ((mpz_ptr, mpz_srcptr));
#endif

#define mpz_nextprime __gmpz_nextprime
__GMP_DECLSPEC void mpz_nextprime __GMP_PROTO ((mpz_ptr, mpz_srcptr));

#define mpz_out_raw __gmpz_out_raw
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpz_out_raw __GMP_PROTO ((FILE *, mpz_srcptr));
#endif

#define mpz_out_str __gmpz_out_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpz_out_str __GMP_PROTO ((FILE *, int, mpz_srcptr));
#endif

#define mpz_perfect_power_p __gmpz_perfect_power_p
__GMP_DECLSPEC int mpz_perfect_power_p __GMP_PROTO ((mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_perfect_square_p __gmpz_perfect_square_p
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p)
__GMP_DECLSPEC int mpz_perfect_square_p __GMP_PROTO ((mpz_srcptr)) 
__GMP_ATTRIBUTE_PURE;
#endif

#define mpz_popcount __gmpz_popcount
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount)
__GMP_DECLSPEC unsigned long int mpz_popcount __GMP_PROTO ((mpz_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
#endif

#define mpz_pow_ui __gmpz_pow_ui
__GMP_DECLSPEC void mpz_pow_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_powm __gmpz_powm
__GMP_DECLSPEC void mpz_powm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_powm_ui __gmpz_powm_ui
__GMP_DECLSPEC void mpz_powm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int, mpz_srcptr));

#define mpz_probab_prime_p __gmpz_probab_prime_p
__GMP_DECLSPEC int mpz_probab_prime_p __GMP_PROTO ((mpz_srcptr, int)) 
__GMP_ATTRIBUTE_PURE;

#define mpz_random __gmpz_random
__GMP_DECLSPEC void mpz_random __GMP_PROTO ((mpz_ptr, mp_size_t));

#define mpz_random2 __gmpz_random2
__GMP_DECLSPEC void mpz_random2 __GMP_PROTO ((mpz_ptr, mp_size_t));

#define mpz_realloc2 __gmpz_realloc2
__GMP_DECLSPEC void mpz_realloc2 __GMP_PROTO ((mpz_ptr, unsigned long));

#define mpz_remove __gmpz_remove
__GMP_DECLSPEC unsigned long int mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_root __gmpz_root
__GMP_DECLSPEC int mpz_root __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_rrandomb __gmpz_rrandomb
__GMP_DECLSPEC void mpz_rrandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, 
unsigned long int));

#define mpz_scan0 __gmpz_scan0
__GMP_DECLSPEC unsigned long int mpz_scan0 __GMP_PROTO ((mpz_srcptr, unsigned 
long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_scan1 __gmpz_scan1
__GMP_DECLSPEC unsigned long int mpz_scan1 __GMP_PROTO ((mpz_srcptr, unsigned 
long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_set __gmpz_set
__GMP_DECLSPEC void mpz_set __GMP_PROTO ((mpz_ptr, mpz_srcptr));

#define mpz_set_d __gmpz_set_d
__GMP_DECLSPEC void mpz_set_d __GMP_PROTO ((mpz_ptr, double));

#define mpz_set_f __gmpz_set_f
__GMP_DECLSPEC void mpz_set_f __GMP_PROTO ((mpz_ptr, mpf_srcptr));

#define mpz_set_q __gmpz_set_q
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q)
__GMP_DECLSPEC void mpz_set_q __GMP_PROTO ((mpz_ptr, mpq_srcptr));
#endif

#define mpz_set_si __gmpz_set_si
__GMP_DECLSPEC void mpz_set_si __GMP_PROTO ((mpz_ptr, signed long int));

#define mpz_set_str __gmpz_set_str
__GMP_DECLSPEC int mpz_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int));

#define mpz_set_ui __gmpz_set_ui
__GMP_DECLSPEC void mpz_set_ui __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_setbit __gmpz_setbit
__GMP_DECLSPEC void mpz_setbit __GMP_PROTO ((mpz_ptr, unsigned long int));

#define mpz_size __gmpz_size
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size)
__GMP_DECLSPEC size_t mpz_size __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;
#endif

#define mpz_sizeinbase __gmpz_sizeinbase
__GMP_DECLSPEC size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_sqrt __gmpz_sqrt
__GMP_DECLSPEC void mpz_sqrt __GMP_PROTO ((mpz_ptr, mpz_srcptr));

#define mpz_sqrtrem __gmpz_sqrtrem
__GMP_DECLSPEC void mpz_sqrtrem __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));

#define mpz_sub __gmpz_sub
__GMP_DECLSPEC void mpz_sub __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_sub_ui __gmpz_sub_ui
__GMP_DECLSPEC void mpz_sub_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long 
int));

#define mpz_ui_sub __gmpz_ui_sub
__GMP_DECLSPEC void mpz_ui_sub __GMP_PROTO ((mpz_ptr, unsigned long int, 
mpz_srcptr));

#define mpz_submul __gmpz_submul
__GMP_DECLSPEC void mpz_submul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_submul_ui __gmpz_submul_ui
__GMP_DECLSPEC void mpz_submul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_swap __gmpz_swap
__GMP_DECLSPEC void mpz_swap __GMP_PROTO ((mpz_ptr, mpz_ptr)) __GMP_NOTHROW;

#define mpz_tdiv_ui __gmpz_tdiv_ui
__GMP_DECLSPEC unsigned long int mpz_tdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned 
long int)) __GMP_ATTRIBUTE_PURE;

#define mpz_tdiv_q __gmpz_tdiv_q
__GMP_DECLSPEC void mpz_tdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp
__GMP_DECLSPEC void mpz_tdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui
__GMP_DECLSPEC unsigned long int mpz_tdiv_q_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_tdiv_qr __gmpz_tdiv_qr
__GMP_DECLSPEC void mpz_tdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, 
mpz_srcptr));

#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui
__GMP_DECLSPEC unsigned long int mpz_tdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_tdiv_r __gmpz_tdiv_r
__GMP_DECLSPEC void mpz_tdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));

#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp
__GMP_DECLSPEC void mpz_tdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned 
long int));

#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui
__GMP_DECLSPEC unsigned long int mpz_tdiv_r_ui __GMP_PROTO ((mpz_ptr, 
mpz_srcptr, unsigned long int));

#define mpz_tstbit __gmpz_tstbit
__GMP_DECLSPEC int mpz_tstbit __GMP_PROTO ((mpz_srcptr, unsigned long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpz_ui_pow_ui __gmpz_ui_pow_ui
__GMP_DECLSPEC void mpz_ui_pow_ui __GMP_PROTO ((mpz_ptr, unsigned long int, 
unsigned long int));

#define mpz_urandomb __gmpz_urandomb
__GMP_DECLSPEC void mpz_urandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, 
unsigned long int));

#define mpz_urandomm __gmpz_urandomm
__GMP_DECLSPEC void mpz_urandomm __GMP_PROTO ((mpz_ptr, gmp_randstate_t, 
mpz_srcptr));

#define mpz_xor __gmpz_xor
#define mpz_eor __gmpz_xor
__GMP_DECLSPEC void mpz_xor __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));


/**************** Rational (i.e. Q) routines.  ****************/

#define mpq_abs __gmpq_abs
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs)
__GMP_DECLSPEC void mpq_abs __GMP_PROTO ((mpq_ptr, mpq_srcptr));
#endif

#define mpq_add __gmpq_add
__GMP_DECLSPEC void mpq_add __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));

#define mpq_canonicalize __gmpq_canonicalize
__GMP_DECLSPEC void mpq_canonicalize __GMP_PROTO ((mpq_ptr));

#define mpq_clear __gmpq_clear
__GMP_DECLSPEC void mpq_clear __GMP_PROTO ((mpq_ptr));

#define mpq_cmp __gmpq_cmp
__GMP_DECLSPEC int mpq_cmp __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) 
__GMP_ATTRIBUTE_PURE;

#define _mpq_cmp_si __gmpq_cmp_si
__GMP_DECLSPEC int _mpq_cmp_si __GMP_PROTO ((mpq_srcptr, long, unsigned long)) 
__GMP_ATTRIBUTE_PURE;

#define _mpq_cmp_ui __gmpq_cmp_ui
__GMP_DECLSPEC int _mpq_cmp_ui __GMP_PROTO ((mpq_srcptr, unsigned long int, 
unsigned long int)) __GMP_ATTRIBUTE_PURE;

#define mpq_div __gmpq_div
__GMP_DECLSPEC void mpq_div __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));

#define mpq_div_2exp __gmpq_div_2exp
__GMP_DECLSPEC void mpq_div_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, unsigned 
long));

#define mpq_equal __gmpq_equal
__GMP_DECLSPEC int mpq_equal __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpq_get_num __gmpq_get_num
__GMP_DECLSPEC void mpq_get_num __GMP_PROTO ((mpz_ptr, mpq_srcptr));

#define mpq_get_den __gmpq_get_den
__GMP_DECLSPEC void mpq_get_den __GMP_PROTO ((mpz_ptr, mpq_srcptr));

#define mpq_get_d __gmpq_get_d
__GMP_DECLSPEC double mpq_get_d __GMP_PROTO ((mpq_srcptr)) __GMP_ATTRIBUTE_PURE;

#define mpq_get_str __gmpq_get_str
__GMP_DECLSPEC char *mpq_get_str __GMP_PROTO ((char *, int, mpq_srcptr));

#define mpq_init __gmpq_init
__GMP_DECLSPEC void mpq_init __GMP_PROTO ((mpq_ptr));

#define mpq_inp_str __gmpq_inp_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, FILE *, int));
#endif

#define mpq_inv __gmpq_inv
__GMP_DECLSPEC void mpq_inv __GMP_PROTO ((mpq_ptr, mpq_srcptr));

#define mpq_mul __gmpq_mul
__GMP_DECLSPEC void mpq_mul __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));

#define mpq_mul_2exp __gmpq_mul_2exp
__GMP_DECLSPEC void mpq_mul_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, unsigned 
long));

#define mpq_neg __gmpq_neg
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg)
__GMP_DECLSPEC void mpq_neg __GMP_PROTO ((mpq_ptr, mpq_srcptr));
#endif

#define mpq_out_str __gmpq_out_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpq_out_str __GMP_PROTO ((FILE *, int, mpq_srcptr));
#endif

#define mpq_set __gmpq_set
__GMP_DECLSPEC void mpq_set __GMP_PROTO ((mpq_ptr, mpq_srcptr));

#define mpq_set_d __gmpq_set_d
__GMP_DECLSPEC void mpq_set_d __GMP_PROTO ((mpq_ptr, double));

#define mpq_set_den __gmpq_set_den
__GMP_DECLSPEC void mpq_set_den __GMP_PROTO ((mpq_ptr, mpz_srcptr));

#define mpq_set_f __gmpq_set_f
__GMP_DECLSPEC void mpq_set_f __GMP_PROTO ((mpq_ptr, mpf_srcptr));

#define mpq_set_num __gmpq_set_num
__GMP_DECLSPEC void mpq_set_num __GMP_PROTO ((mpq_ptr, mpz_srcptr));

#define mpq_set_si __gmpq_set_si
__GMP_DECLSPEC void mpq_set_si __GMP_PROTO ((mpq_ptr, signed long int, unsigned 
long int));

#define mpq_set_str __gmpq_set_str
__GMP_DECLSPEC int mpq_set_str __GMP_PROTO ((mpq_ptr, const char *, int));

#define mpq_set_ui __gmpq_set_ui
__GMP_DECLSPEC void mpq_set_ui __GMP_PROTO ((mpq_ptr, unsigned long int, 
unsigned long int));

#define mpq_set_z __gmpq_set_z
__GMP_DECLSPEC void mpq_set_z __GMP_PROTO ((mpq_ptr, mpz_srcptr));

#define mpq_sub __gmpq_sub
__GMP_DECLSPEC void mpq_sub __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));

#define mpq_swap __gmpq_swap
__GMP_DECLSPEC void mpq_swap __GMP_PROTO ((mpq_ptr, mpq_ptr)) __GMP_NOTHROW;


/**************** Float (i.e. F) routines.  ****************/

#define mpf_abs __gmpf_abs
__GMP_DECLSPEC void mpf_abs __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_add __gmpf_add
__GMP_DECLSPEC void mpf_add __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));

#define mpf_add_ui __gmpf_add_ui
__GMP_DECLSPEC void mpf_add_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long 
int));
#define mpf_ceil __gmpf_ceil
__GMP_DECLSPEC void mpf_ceil __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_clear __gmpf_clear
__GMP_DECLSPEC void mpf_clear __GMP_PROTO ((mpf_ptr));

#define mpf_cmp __gmpf_cmp
__GMP_DECLSPEC int mpf_cmp __GMP_PROTO ((mpf_srcptr, mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_cmp_d __gmpf_cmp_d
__GMP_DECLSPEC int mpf_cmp_d __GMP_PROTO ((mpf_srcptr, double)) 
__GMP_ATTRIBUTE_PURE;

#define mpf_cmp_si __gmpf_cmp_si
__GMP_DECLSPEC int mpf_cmp_si __GMP_PROTO ((mpf_srcptr, signed long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpf_cmp_ui __gmpf_cmp_ui
__GMP_DECLSPEC int mpf_cmp_ui __GMP_PROTO ((mpf_srcptr, unsigned long int)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpf_div __gmpf_div
__GMP_DECLSPEC void mpf_div __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));

#define mpf_div_2exp __gmpf_div_2exp
__GMP_DECLSPEC void mpf_div_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned 
long int));

#define mpf_div_ui __gmpf_div_ui
__GMP_DECLSPEC void mpf_div_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long 
int));

#define mpf_dump __gmpf_dump
__GMP_DECLSPEC void mpf_dump __GMP_PROTO ((mpf_srcptr));

#define mpf_eq __gmpf_eq
__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, unsigned long 
int)) __GMP_ATTRIBUTE_PURE;

#define mpf_fits_sint_p __gmpf_fits_sint_p
__GMP_DECLSPEC int mpf_fits_sint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_fits_slong_p __gmpf_fits_slong_p
__GMP_DECLSPEC int mpf_fits_slong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_fits_sshort_p __gmpf_fits_sshort_p
__GMP_DECLSPEC int mpf_fits_sshort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_fits_uint_p __gmpf_fits_uint_p
__GMP_DECLSPEC int mpf_fits_uint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_fits_ulong_p __gmpf_fits_ulong_p
__GMP_DECLSPEC int mpf_fits_ulong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_fits_ushort_p __gmpf_fits_ushort_p
__GMP_DECLSPEC int mpf_fits_ushort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_floor __gmpf_floor
__GMP_DECLSPEC void mpf_floor __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_get_d __gmpf_get_d
__GMP_DECLSPEC double mpf_get_d __GMP_PROTO ((mpf_srcptr)) __GMP_ATTRIBUTE_PURE;

#define mpf_get_d_2exp __gmpf_get_d_2exp
__GMP_DECLSPEC double mpf_get_d_2exp __GMP_PROTO ((signed long int *, 
mpf_srcptr));

#define mpf_get_default_prec __gmpf_get_default_prec
__GMP_DECLSPEC unsigned long int mpf_get_default_prec __GMP_PROTO ((void)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpf_get_prec __gmpf_get_prec
__GMP_DECLSPEC unsigned long int mpf_get_prec __GMP_PROTO ((mpf_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpf_get_si __gmpf_get_si
__GMP_DECLSPEC long mpf_get_si __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_get_str __gmpf_get_str
__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, size_t, 
mpf_srcptr));

#define mpf_get_ui __gmpf_get_ui
__GMP_DECLSPEC unsigned long mpf_get_ui __GMP_PROTO ((mpf_srcptr)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpf_init __gmpf_init
__GMP_DECLSPEC void mpf_init __GMP_PROTO ((mpf_ptr));

#define mpf_init2 __gmpf_init2
__GMP_DECLSPEC void mpf_init2 __GMP_PROTO ((mpf_ptr, unsigned long int));

#define mpf_init_set __gmpf_init_set
__GMP_DECLSPEC void mpf_init_set __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_init_set_d __gmpf_init_set_d
__GMP_DECLSPEC void mpf_init_set_d __GMP_PROTO ((mpf_ptr, double));

#define mpf_init_set_si __gmpf_init_set_si
__GMP_DECLSPEC void mpf_init_set_si __GMP_PROTO ((mpf_ptr, signed long int));

#define mpf_init_set_str __gmpf_init_set_str
__GMP_DECLSPEC int mpf_init_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, 
int));

#define mpf_init_set_ui __gmpf_init_set_ui
__GMP_DECLSPEC void mpf_init_set_ui __GMP_PROTO ((mpf_ptr, unsigned long int));

#define mpf_inp_str __gmpf_inp_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, FILE *, int));
#endif

#define mpf_integer_p __gmpf_integer_p
__GMP_DECLSPEC int mpf_integer_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_mul __gmpf_mul
__GMP_DECLSPEC void mpf_mul __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));

#define mpf_mul_2exp __gmpf_mul_2exp
__GMP_DECLSPEC void mpf_mul_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned 
long int));

#define mpf_mul_ui __gmpf_mul_ui
__GMP_DECLSPEC void mpf_mul_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long 
int));

#define mpf_neg __gmpf_neg
__GMP_DECLSPEC void mpf_neg __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_out_str __gmpf_out_str
#ifdef _GMP_H_HAVE_FILE
__GMP_DECLSPEC size_t mpf_out_str __GMP_PROTO ((FILE *, int, size_t, 
mpf_srcptr));
#endif

#define mpf_pow_ui __gmpf_pow_ui
__GMP_DECLSPEC void mpf_pow_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long 
int));

#define mpf_random2 __gmpf_random2
__GMP_DECLSPEC void mpf_random2 __GMP_PROTO ((mpf_ptr, mp_size_t, mp_exp_t));

#define mpf_reldiff __gmpf_reldiff
__GMP_DECLSPEC void mpf_reldiff __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));

#define mpf_set __gmpf_set
__GMP_DECLSPEC void mpf_set __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_set_d __gmpf_set_d
__GMP_DECLSPEC void mpf_set_d __GMP_PROTO ((mpf_ptr, double));

#define mpf_set_default_prec __gmpf_set_default_prec
__GMP_DECLSPEC void mpf_set_default_prec __GMP_PROTO ((unsigned long int)) 
__GMP_NOTHROW;

#define mpf_set_prec __gmpf_set_prec
__GMP_DECLSPEC void mpf_set_prec __GMP_PROTO ((mpf_ptr, unsigned long int));

#define mpf_set_prec_raw __gmpf_set_prec_raw
__GMP_DECLSPEC void mpf_set_prec_raw __GMP_PROTO ((mpf_ptr, unsigned long int)) 
__GMP_NOTHROW;

#define mpf_set_q __gmpf_set_q
__GMP_DECLSPEC void mpf_set_q __GMP_PROTO ((mpf_ptr, mpq_srcptr));

#define mpf_set_si __gmpf_set_si
__GMP_DECLSPEC void mpf_set_si __GMP_PROTO ((mpf_ptr, signed long int));

#define mpf_set_str __gmpf_set_str
__GMP_DECLSPEC int mpf_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int));

#define mpf_set_ui __gmpf_set_ui
__GMP_DECLSPEC void mpf_set_ui __GMP_PROTO ((mpf_ptr, unsigned long int));

#define mpf_set_z __gmpf_set_z
__GMP_DECLSPEC void mpf_set_z __GMP_PROTO ((mpf_ptr, mpz_srcptr));

#define mpf_size __gmpf_size
__GMP_DECLSPEC size_t mpf_size __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW 
__GMP_ATTRIBUTE_PURE;

#define mpf_sqrt __gmpf_sqrt
__GMP_DECLSPEC void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_sqrt_ui __gmpf_sqrt_ui
__GMP_DECLSPEC void mpf_sqrt_ui __GMP_PROTO ((mpf_ptr, unsigned long int));

#define mpf_sub __gmpf_sub
__GMP_DECLSPEC void mpf_sub __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));

#define mpf_sub_ui __gmpf_sub_ui
__GMP_DECLSPEC void mpf_sub_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long 
int));

#define mpf_swap __gmpf_swap
__GMP_DECLSPEC void mpf_swap __GMP_PROTO ((mpf_ptr, mpf_ptr)) __GMP_NOTHROW;

#define mpf_trunc __gmpf_trunc
__GMP_DECLSPEC void mpf_trunc __GMP_PROTO ((mpf_ptr, mpf_srcptr));

#define mpf_ui_div __gmpf_ui_div
__GMP_DECLSPEC void mpf_ui_div __GMP_PROTO ((mpf_ptr, unsigned long int, 
mpf_srcptr));

#define mpf_ui_sub __gmpf_ui_sub
__GMP_DECLSPEC void mpf_ui_sub __GMP_PROTO ((mpf_ptr, unsigned long int, 
mpf_srcptr));

#define mpf_urandomb __gmpf_urandomb
__GMP_DECLSPEC void mpf_urandomb __GMP_PROTO ((mpf_t, gmp_randstate_t, unsigned 
long int));


/************ Low level positive-integer (i.e. N) routines.  ************/

/* This is ugly, but we need to make user calls reach the prefixed function. */

#define mpn_add __MPN(add)
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add)
__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_srcptr,mp_size_t));
#endif

#define mpn_add_1 __MPN(add_1)
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1)
__GMP_DECLSPEC mp_limb_t mpn_add_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_limb_t)) __GMP_NOTHROW;
#endif

#define mpn_add_n __MPN(add_n)
__GMP_DECLSPEC mp_limb_t mpn_add_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, 
mp_size_t));

#define mpn_addmul_1 __MPN(addmul_1)
__GMP_DECLSPEC mp_limb_t mpn_addmul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, 
mp_size_t, mp_limb_t));

#define mpn_bdivmod __MPN(bdivmod)
__GMP_DECLSPEC mp_limb_t mpn_bdivmod __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, 
mp_srcptr, mp_size_t, unsigned long int));

#define mpn_cmp __MPN(cmp)
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp)
__GMP_DECLSPEC int mpn_cmp __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) 
__GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
#endif

#define mpn_divexact_by3(dst,src,size) \
  mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0))

#define mpn_divexact_by3c __MPN(divexact_by3c)
__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c __GMP_PROTO ((mp_ptr, mp_srcptr, 
mp_size_t, mp_limb_t));

#define mpn_divmod_1(qp,np,nsize,dlimb) \
  mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb)

#define mpn_divrem __MPN(divrem)
__GMP_DECLSPEC mp_limb_t mpn_divrem __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, 
mp_size_t, mp_srcptr, mp_size_t));

#define mpn_divrem_1 __MPN(divrem_1)
__GMP_DECLSPEC mp_limb_t mpn_divrem_1 __GMP_PROTO ((mp_ptr, mp_size_t, 
mp_srcptr, mp_size_t, mp_limb_t));

#define mpn_divrem_2 __MPN(divrem_2)
__GMP_DECLSPEC mp_limb_t mpn_divrem_2 __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, 
mp_size_t, mp_srcptr));

#define mpn_gcd __MPN(gcd)
__GMP_DECLSPEC mp_size_t mpn_gcd __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, 
mp_ptr, mp_size_t));

#define mpn_gcd_1 __MPN(gcd_1)
__GMP_DECLSPEC mp_limb_t mpn_gcd_1 __GMP_PROTO ((mp_srcptr, mp_size_t, 
mp_limb_t)) __GMP_ATTRIBUTE_PURE;

#define mpn_gcdext __MPN(gcdext)
__GMP_DECLSPEC mp_size_t mpn_gcdext __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t *, 
mp_ptr, mp_size_t, mp_ptr, mp_size_t));

#define mpn_get_str __MPN(get_str)
__GMP_DECLSPEC size_t mpn_get_str __GMP_PROTO ((unsigned char *, int, mp_ptr, 
mp_size_t));

#define mpn_hamdist __MPN(hamdist)
__GMP_DECLSPEC unsigned long int mpn_hamdist __GMP_PROTO ((mp_srcptr, 
mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpn_lshift __MPN(lshift)
__GMP_DECLSPEC mp_limb_t mpn_lshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
unsigned int));

#define mpn_mod_1 __MPN(mod_1)
__GMP_DECLSPEC mp_limb_t mpn_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, 
mp_limb_t)) __GMP_ATTRIBUTE_PURE;

#define mpn_mul __MPN(mul)
__GMP_DECLSPEC mp_limb_t mpn_mul __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_srcptr, mp_size_t));

#define mpn_mul_1 __MPN(mul_1)
__GMP_DECLSPEC mp_limb_t mpn_mul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_limb_t));

#define mpn_mul_n __MPN(mul_n)
__GMP_DECLSPEC void mpn_mul_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, 
mp_size_t));

#define mpn_perfect_square_p __MPN(perfect_square_p)
__GMP_DECLSPEC int mpn_perfect_square_p __GMP_PROTO ((mp_srcptr, mp_size_t)) 
__GMP_ATTRIBUTE_PURE;

#define mpn_popcount __MPN(popcount)
__GMP_DECLSPEC unsigned long int mpn_popcount __GMP_PROTO ((mp_srcptr, 
mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;

#define mpn_pow_1 __MPN(pow_1)
__GMP_DECLSPEC mp_size_t mpn_pow_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_limb_t, mp_ptr));

/* undocumented now, but retained here for upward compatibility */
#define mpn_preinv_mod_1 __MPN(preinv_mod_1)
__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, 
mp_limb_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE;

#define mpn_random __MPN(random)
__GMP_DECLSPEC void mpn_random __GMP_PROTO ((mp_ptr, mp_size_t));

#define mpn_random2 __MPN(random2)
__GMP_DECLSPEC void mpn_random2 __GMP_PROTO ((mp_ptr, mp_size_t));

#define mpn_rshift __MPN(rshift)
__GMP_DECLSPEC mp_limb_t mpn_rshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
unsigned int));

#define mpn_scan0 __MPN(scan0)
__GMP_DECLSPEC unsigned long int mpn_scan0 __GMP_PROTO ((mp_srcptr, unsigned 
long int)) __GMP_ATTRIBUTE_PURE;

#define mpn_scan1 __MPN(scan1)
__GMP_DECLSPEC unsigned long int mpn_scan1 __GMP_PROTO ((mp_srcptr, unsigned 
long int)) __GMP_ATTRIBUTE_PURE;

#define mpn_set_str __MPN(set_str)
__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned 
char *, size_t, int));

#define mpn_sqrtrem __MPN(sqrtrem)
__GMP_DECLSPEC mp_size_t mpn_sqrtrem __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, 
mp_size_t));

#define mpn_sub __MPN(sub)
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub)
__GMP_DECLSPEC mp_limb_t mpn_sub __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_srcptr,mp_size_t));
#endif

#define mpn_sub_1 __MPN(sub_1)
#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1)
__GMP_DECLSPEC mp_limb_t mpn_sub_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, 
mp_limb_t)) __GMP_NOTHROW;
#endif

#define mpn_sub_n __MPN(sub_n)
__GMP_DECLSPEC mp_limb_t mpn_sub_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, 
mp_size_t));

#define mpn_submul_1 __MPN(submul_1)
__GMP_DECLSPEC mp_limb_t mpn_submul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, 
mp_size_t, mp_limb_t));

#define mpn_tdiv_qr __MPN(tdiv_qr)
__GMP_DECLSPEC void mpn_tdiv_qr __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, 
mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));


/**************** mpz inlines ****************/

/* The following are provided as inlines where possible, but always exist as
   library functions too, for binary compatibility.

   Within gmp itself this inlining generally isn't relied on, since it
   doesn't get done for all compilers, whereas if something is worth
   inlining then it's worth arranging always.

   There are two styles of inlining here.  When the same bit of code is
   wanted for the inline as for the library version, then __GMP_FORCE_foo
   arranges for that code to be emitted and the __GMP_EXTERN_INLINE
   directive suppressed, eg. mpz_fits_uint_p.  When a different bit of code
   is wanted for the inline than for the library version, then
   __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs.  */

#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs)
__GMP_EXTERN_INLINE void
mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u)
{
  if (__gmp_w != __gmp_u)
    mpz_set (__gmp_w, __gmp_u);
  __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size);
}
#endif

#if GMP_NAIL_BITS == 0
#define __GMPZ_FITS_UTYPE_P(z,maxval)                                   \
  mp_size_t  __gmp_n = z->_mp_size;                                     \
  mp_ptr  __gmp_p = z->_mp_d;                                           \
  return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval));
#else
#define __GMPZ_FITS_UTYPE_P(z,maxval)                                   \
  mp_size_t  __gmp_n = z->_mp_size;                                     \
  mp_ptr  __gmp_p = z->_mp_d;                                           \
  return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)        \
          || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> 
GMP_NUMB_BITS)));
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p)
#if ! defined (__GMP_FORCE_mpz_fits_uint_p)
__GMP_EXTERN_INLINE
#endif
int
mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_UINT_MAX);
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p)
#if ! defined (__GMP_FORCE_mpz_fits_ulong_p)
__GMP_EXTERN_INLINE
#endif
int
mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_ULONG_MAX);
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p)
#if ! defined (__GMP_FORCE_mpz_fits_ushort_p)
__GMP_EXTERN_INLINE
#endif
int
mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_USHRT_MAX);
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui)
#if ! defined (__GMP_FORCE_mpz_get_ui)
__GMP_EXTERN_INLINE
#endif
unsigned long
mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  mp_ptr __gmp_p = __gmp_z->_mp_d;
  mp_size_t __gmp_n = __gmp_z->_mp_size;
  mp_limb_t __gmp_l = __gmp_p[0];
  if (__GMP_ULONG_MAX <= GMP_NUMB_MASK)
    return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
#if GMP_NAIL_BITS != 0  /* redundant #if, shuts up compiler warnings */
  else                  /* happens for nails, but not if LONG_LONG_LIMB */
    {                   /* assume two limbs are enough to fill an ulong */
      __gmp_n = __GMP_ABS (__gmp_n);
      if (__gmp_n <= 1)
        return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
      else
        return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS);
    }
#endif
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn)
#if ! defined (__GMP_FORCE_mpz_getlimbn)
__GMP_EXTERN_INLINE
#endif
mp_limb_t
mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW
{
  if (__GMP_ABS (__gmp_z->_mp_size) <= __gmp_n || __gmp_n < 0)
    return 0;
  else
    return __gmp_z->_mp_d[__gmp_n];
}
#endif

#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg)
__GMP_EXTERN_INLINE void
mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u)
{
  if (__gmp_w != __gmp_u)
    mpz_set (__gmp_w, __gmp_u);
  __gmp_w->_mp_size = - __gmp_w->_mp_size;
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p)
#if ! defined (__GMP_FORCE_mpz_perfect_square_p)
__GMP_EXTERN_INLINE
#endif
int
mpz_perfect_square_p (mpz_srcptr __gmp_a)
{
  mp_size_t __gmp_asize = __gmp_a->_mp_size;
  if (__gmp_asize <= 0)
    return (__gmp_asize == 0);  /* zero is a square, negatives are not */
  else
    return mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize);
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount)
#if ! defined (__GMP_FORCE_mpz_popcount)
__GMP_EXTERN_INLINE
#endif
unsigned long
mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW
{
  mp_size_t __gmp_usize = __gmp_u->_mp_size;

  if (__gmp_usize <= 0)
    return (__gmp_usize < 0 ? __GMP_ULONG_MAX : 0);
  else
    return mpn_popcount (__gmp_u->_mp_d, __gmp_usize);
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q)
#if ! defined (__GMP_FORCE_mpz_set_q)
__GMP_EXTERN_INLINE
#endif
void
mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u)
{
  mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u));
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size)
#if ! defined (__GMP_FORCE_mpz_size)
__GMP_EXTERN_INLINE
#endif
size_t
mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  return __GMP_ABS (__gmp_z->_mp_size);
}
#endif


/**************** mpq inlines ****************/

#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs)
__GMP_EXTERN_INLINE void
mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u)
{
  if (__gmp_w != __gmp_u)
    mpq_set (__gmp_w, __gmp_u);
  __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size);
}
#endif

#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg)
__GMP_EXTERN_INLINE void
mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u)
{
  if (__gmp_w != __gmp_u)
    mpq_set (__gmp_w, __gmp_u);
  __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size;
}
#endif


/**************** mpn inlines ****************/

/* The comments with __GMPN_ADD_1 below apply here too.

   The test for FUNCTION returning 0 should predict well.  If it's assumed
   {yp,ysize} will usually have a random number of bits then the high limb
   won't be full and a carry out will occur a good deal less than 50% of the
   time.

   ysize==0 isn't a documented feature, but is used internally in a few
   places.

   Producing cout last stops it using up a register during the main part of
   the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))"
   doesn't seem able to move the true and false legs of the conditional up
   to the two places cout is generated.  */

#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST)     \
  do {                                                                  \
    mp_size_t  __gmp_i;                                                 \
    mp_limb_t  __gmp_x;                                                 \
                                                                        \
    /* ASSERT ((ysize) >= 0); */                                        \
    /* ASSERT ((xsize) >= (ysize)); */                                  \
    /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */      \
    /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */      \
                                                                        \
    __gmp_i = (ysize);                                                  \
    if (__gmp_i != 0)                                                   \
      {                                                                 \
        if (FUNCTION (wp, xp, yp, __gmp_i))                             \
          {                                                             \
            do                                                          \
              {                                                         \
                if (__gmp_i >= (xsize))                                 \
                  {                                                     \
                    (cout) = 1;                                         \
                    goto __gmp_done;                                    \
                  }                                                     \
                __gmp_x = (xp)[__gmp_i];                                \
              }                                                         \
            while (TEST);                                               \
          }                                                             \
      }                                                                 \
    if ((wp) != (xp))                                                   \
      __GMPN_COPY_REST (wp, xp, xsize, __gmp_i);                        \
    (cout) = 0;                                                         \
  __gmp_done:                                                           \
    ;                                                                   \
  } while (0)

#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize)              \
  __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n,       \
               (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0))
#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize)              \
  __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n,       \
               (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 
0))


/* The use of __gmp_i indexing is designed to ensure a compile time src==dst
   remains nice and clear to the compiler, so that __GMPN_COPY_REST can
   disappear, and the load/add/store gets a chance to become a
   read-modify-write on CISC CPUs.

   Alternatives:

   Using a pair of pointers instead of indexing would be possible, but gcc
   isn't able to recognise compile-time src==dst in that case, even when the
   pointers are incremented more or less together.  Other compilers would
   very likely have similar difficulty.

   gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or
   similar to detect a compile-time src==dst.  This works nicely on gcc
   2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems
   to be always false, for a pointer p.  But the current code form seems
   good enough for src==dst anyway.

   gcc on x86 as usual doesn't give particularly good flags handling for the
   carry/borrow detection.  It's tempting to want some multi instruction asm
   blocks to help it, and this was tried, but in truth there's only a few
   instructions to save and any gain is all too easily lost by register
   juggling setting up for the asm.  */

#if GMP_NAIL_BITS == 0
#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB)             \
  do {                                                          \
    mp_size_t  __gmp_i;                                         \
    mp_limb_t  __gmp_x, __gmp_r;                                \
                                                                \
    /* ASSERT ((n) >= 1); */                                    \
    /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */        \
                                                                \
    __gmp_x = (src)[0];                                         \
    __gmp_r = __gmp_x OP (v);                                   \
    (dst)[0] = __gmp_r;                                         \
    if (CB (__gmp_r, __gmp_x, (v)))                             \
      {                                                         \
        (cout) = 1;                                             \
        for (__gmp_i = 1; __gmp_i < (n);)                       \
          {                                                     \
            __gmp_x = (src)[__gmp_i];                           \
            __gmp_r = __gmp_x OP 1;                             \
            (dst)[__gmp_i] = __gmp_r;                           \
            ++__gmp_i;                                          \
            if (!CB (__gmp_r, __gmp_x, 1))                      \
              {                                                 \
                if ((src) != (dst))                             \
                  __GMPN_COPY_REST (dst, src, n, __gmp_i);      \
                (cout) = 0;                                     \
                break;                                          \
              }                                                 \
          }                                                     \
      }                                                         \
    else                                                        \
      {                                                         \
        if ((src) != (dst))                                     \
          __GMPN_COPY_REST (dst, src, n, 1);                    \
        (cout) = 0;                                             \
      }                                                         \
  } while (0)
#endif

#if GMP_NAIL_BITS >= 1
#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB)             \
  do {                                                          \
    mp_size_t  __gmp_i;                                         \
    mp_limb_t  __gmp_x, __gmp_r;                                \
                                                                \
    /* ASSERT ((n) >= 1); */                                    \
    /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */        \
                                                                \
    __gmp_x = (src)[0];                                         \
    __gmp_r = __gmp_x OP (v);                                   \
    (dst)[0] = __gmp_r & GMP_NUMB_MASK;                         \
    if (__gmp_r >> GMP_NUMB_BITS != 0)                          \
      {                                                         \
        (cout) = 1;                                             \
        for (__gmp_i = 1; __gmp_i < (n);)                       \
          {                                                     \
            __gmp_x = (src)[__gmp_i];                           \
            __gmp_r = __gmp_x OP 1;                             \
            (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK;           \
            ++__gmp_i;                                          \
            if (__gmp_r >> GMP_NUMB_BITS == 0)                  \
              {                                                 \
                if ((src) != (dst))                             \
                  __GMPN_COPY_REST (dst, src, n, __gmp_i);      \
                (cout) = 0;                                     \
                break;                                          \
              }                                                 \
          }                                                     \
      }                                                         \
    else                                                        \
      {                                                         \
        if ((src) != (dst))                                     \
          __GMPN_COPY_REST (dst, src, n, 1);                    \
        (cout) = 0;                                             \
      }                                                         \
  } while (0)
#endif

#define __GMPN_ADDCB(r,x,y) ((r) < (y))
#define __GMPN_SUBCB(r,x,y) ((x) < (y))

#define __GMPN_ADD_1(cout, dst, src, n, v)           \
  __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB)
#define __GMPN_SUB_1(cout, dst, src, n, v)           \
  __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB)


/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or
   negative.  size==0 is allowed.  On random data usually only one limb will
   need to be examined to get a result, so it's worth having it inline.  */
#define __GMPN_CMP(result, xp, yp, size)                                \
  do {                                                                  \
    mp_size_t  __gmp_i;                                                 \
    mp_limb_t  __gmp_x, __gmp_y;                                        \
                                                                        \
    /* ASSERT ((size) >= 0); */                                         \
                                                                        \
    (result) = 0;                                                       \
    __gmp_i = (size);                                                   \
    while (--__gmp_i >= 0)                                              \
      {                                                                 \
        __gmp_x = (xp)[__gmp_i];                                        \
        __gmp_y = (yp)[__gmp_i];                                        \
        if (__gmp_x != __gmp_y)                                         \
          {                                                             \
            /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */   \
            (result) = (__gmp_x > __gmp_y ? 1 : -1);                    \
            break;                                                      \
          }                                                             \
      }                                                                 \
  } while (0)


/* For power and powerpc we want an inline ldu/stu/bdnz loop for copying.
   On ppc630 for instance this is optimal since it can sustain only 1 store
   per cycle.

   gcc 2.95.x (powerpc64 -maix64, or powerpc32) doesn't recognise the "for"
   loop in the generic code below can become ldu/stu/bdnz.  The do/while
   here helps it get to that.

   In gcc -mpowerpc64 mode, without -maix64, __size seems to want to be an
   mp_limb_t to get into the ctr register, and even then the loop is a
   curious ldu/stu/bdz/b.  But let's not worry about that unless there's a
   system using this.  An asm block could force what we want if necessary.

   xlc 3.1 already generates ldu/stu/bdnz from the generic C, and does so
   from this loop too.  */

#if __GMP_HAVE_HOST_CPU_FAMILY_power || __GMP_HAVE_HOST_CPU_FAMILY_powerpc
#define __GMPN_COPY_INCR(dst, src, size)                        \
  do {                                                          \
    /* ASSERT ((size) >= 0); */                                 \
    /* ASSERT (MPN_SAME_OR_INCR_P (dst, src, size)); */         \
    if ((size) != 0)                                            \
      {                                                         \
        mp_ptr     __gmp_copy_incr_dst = (dst) - 1;             \
        mp_srcptr  __gmp_copy_incr_src = (src) - 1;             \
        mp_size_t  __gmp_copy_incr_size = (size);               \
        do                                                      \
          *++__gmp_copy_incr_dst = *++__gmp_copy_incr_src;      \
        while (--__gmp_copy_incr_size != 0);                    \
      }                                                         \
  } while (0)
#define __GMPN_COPY(dst, src, size)                             \
  do {                                                          \
    /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */     \
    __GMPN_COPY_INCR (dst, src, size);                          \
  } while (0)
#endif

#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST)
#define __GMPN_COPY_REST(dst, src, size, start)                 \
  do {                                                          \
    /* ASSERT ((start) >= 0); */                                \
    /* ASSERT ((start) <= (size)); */                           \
    __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \
  } while (0)
#endif

/* Copy {src,size} to {dst,size}, starting at "start".  This is designed to
   keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1,
   __GMPN_ADD, etc.  */
#if ! defined (__GMPN_COPY_REST)
#define __GMPN_COPY_REST(dst, src, size, start)                 \
  do {                                                          \
    mp_size_t __gmp_j;                                          \
    /* ASSERT ((size) >= 0); */                                 \
    /* ASSERT ((start) >= 0); */                                \
    /* ASSERT ((start) <= (size)); */                           \
    /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */     \
    for (__gmp_j = (start); __gmp_j < (size); __gmp_j++)        \
      (dst)[__gmp_j] = (src)[__gmp_j];                          \
  } while (0)
#endif

/* Enhancement: Use some of the smarter code from gmp-impl.h.  Maybe use
   mpn_copyi if there's a native version, and if we don't mind demanding
   binary compatibility for it (on targets which use it).  */

#if ! defined (__GMPN_COPY)
#define __GMPN_COPY(dst, src, size)   __GMPN_COPY_REST (dst, src, size, 0)
#endif


#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add)
#if ! defined (__GMP_FORCE_mpn_add)
__GMP_EXTERN_INLINE
#endif
mp_limb_t
mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr 
__gmp_yp, mp_size_t __gmp_ysize)
{
  mp_limb_t  __gmp_c;
  __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize);
  return __gmp_c;
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1)
#if ! defined (__GMP_FORCE_mpn_add_1)
__GMP_EXTERN_INLINE
#endif
mp_limb_t
mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, 
mp_limb_t __gmp_n) __GMP_NOTHROW
{
  mp_limb_t  __gmp_c;
  __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n);
  return __gmp_c;
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp)
#if ! defined (__GMP_FORCE_mpn_cmp)
__GMP_EXTERN_INLINE
#endif
int
mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) 
__GMP_NOTHROW
{
  int __gmp_result;
  __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size);
  return __gmp_result;
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub)
#if ! defined (__GMP_FORCE_mpn_sub)
__GMP_EXTERN_INLINE
#endif
mp_limb_t
mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr 
__gmp_yp, mp_size_t __gmp_ysize)
{
  mp_limb_t  __gmp_c;
  __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize);
  return __gmp_c;
}
#endif

#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1)
#if ! defined (__GMP_FORCE_mpn_sub_1)
__GMP_EXTERN_INLINE
#endif
mp_limb_t
mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, 
mp_limb_t __gmp_n) __GMP_NOTHROW
{
  mp_limb_t  __gmp_c;
  __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n);
  return __gmp_c;
}
#endif

#if defined (__cplusplus)
}
#endif


/* Allow faster testing for negative, zero, and positive.  */
#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)

/* When using GCC, optimize certain common comparisons.  */
#if defined (__GNUC__)
#define mpz_cmp_ui(Z,UI) \
  (__builtin_constant_p (UI) && (UI) == 0                               \
   ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI))
#define mpz_cmp_si(Z,SI) \
  (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z)                 \
   : __builtin_constant_p (SI) && (SI) > 0                              \
    ? _mpz_cmp_ui (Z, __GMP_CAST (unsigned long int, SI))               \
   : _mpz_cmp_si (Z,SI))
#define mpq_cmp_ui(Q,NUI,DUI) \
  (__builtin_constant_p (NUI) && (NUI) == 0                             \
   ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI))
#define mpq_cmp_si(q,n,d)                       \
  (__builtin_constant_p ((n) >= 0) && (n) >= 0  \
   ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \
   : _mpq_cmp_si (q, n, d))
#else
#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI)
#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI)
#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI)
#define mpq_cmp_si(q,n,d)  _mpq_cmp_si(q,n,d)
#endif


/* Using "&" rather than "&&" means these can come out branch-free.  Every
   mpz_t has at least one limb allocated, so fetching the low limb is always
   allowed.  */
#define mpz_odd_p(z)   (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0]))
#define mpz_even_p(z)  (! mpz_odd_p (z))


/**************** C++ routines ****************/

#ifdef __cplusplus
__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr);
__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr);
__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr);
__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr);
__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr);
__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr);
#endif


/* Compatibility with GMP 2 and earlier. */
#define mpn_divmod(qp,np,nsize,dp,dsize) \
  mpn_divrem (qp, (mp_size_t) 0, np, nsize, dp, dsize)

/* Compatibility with GMP 1.  */
#define mpz_mdiv        mpz_fdiv_q
#define mpz_mdivmod     mpz_fdiv_qr
#define mpz_mmod        mpz_fdiv_r
#define mpz_mdiv_ui     mpz_fdiv_q_ui
#define mpz_mdivmod_ui(q,r,n,d) \
  (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
#define mpz_mmod_ui(r,n,d) \
  (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))

/* Useful synonyms, but not quite compatible with GMP 1.  */
#define mpz_div         mpz_fdiv_q
#define mpz_divmod      mpz_fdiv_qr
#define mpz_div_ui      mpz_fdiv_q_ui
#define mpz_divmod_ui   mpz_fdiv_qr_ui
#define mpz_mod_ui      mpz_fdiv_r_ui
#define mpz_div_2exp    mpz_fdiv_q_2exp
#define mpz_mod_2exp    mpz_fdiv_r_2exp

enum
{
  GMP_ERROR_NONE = 0,
  GMP_ERROR_UNSUPPORTED_ARGUMENT = 1,
  GMP_ERROR_DIVISION_BY_ZERO = 2,
  GMP_ERROR_SQRT_OF_NEGATIVE = 4,
  GMP_ERROR_INVALID_ARGUMENT = 8,
  GMP_ERROR_ALLOCATE = 16,
  GMP_ERROR_BAD_STRING = 32,
  GMP_ERROR_UNUSED_ERROR
};

/* Major version number is the value of __GNU_MP__ too, above and in mp.h. */
#define __GNU_MP_VERSION 4
#define __GNU_MP_VERSION_MINOR 1
#define __GNU_MP_VERSION_PATCHLEVEL 4

#define __GMP_H__
#endif /* __GMP_H__ */
/* gmpxx.h -- C++ class wrapper for GMP types.  -*- C++ -*-

Copyright 2001, 2002, 2003 Free Software Foundation, Inc.

This file is part of the GNU MP Library.

The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.

The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */

/* the C++ compiler must implement the following features:
   - member templates
   - partial specialization of templates
   - namespace support
   for g++, this means version 2.91 or higher
   for other compilers, I don't know */
#ifdef __GNUC__
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 91)
#error gmpxx.h requires g++ version 2.91 (egcs 1.1.2) or higher
#endif
#endif

#ifndef __GMP_PLUSPLUS__
#define __GMP_PLUSPLUS__

#include <iosfwd>
#include <string>
#include <gmp.h>


/**************** Function objects ****************/
/* Any evaluation of a __gmp_expr ends up calling one of these functions
   all intermediate functions being inline, the evaluation should optimize
   to a direct call to the relevant function, thus yielding no overhead
   over the C interface.
   Functions with mpfr_t arguments are wrapped by an #ifdef test because
   mpfr isn't installed by default */

struct __gmp_unary_plus
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_set(z, w); }
  static void eval(mpq_ptr q, mpq_srcptr r) { mpq_set(q, r); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_set(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_set(f, g, mode); }
#endif
};

struct __gmp_unary_minus
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_neg(z, w); }
  static void eval(mpq_ptr q, mpq_srcptr r) { mpq_neg(q, r); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_neg(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_neg(f, g, mode); }
#endif
};

struct __gmp_unary_com
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_com(z, w); }
};

struct __gmp_binary_plus
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_add(z, w, v); }

  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_add_ui(z, w, l); }
  static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
  { mpz_add_ui(z, w, l); }
  static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
  {
    if (l >= 0)
      mpz_add_ui(z, w, l);
    else
      mpz_sub_ui(z, w, -l);
  }
  static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
  {
    if (l >= 0)
      mpz_add_ui(z, w, l);
    else
      mpz_sub_ui(z, w, -l);
  }
  static void eval(mpz_ptr z, mpz_srcptr w, double d)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_add(z, w, temp);
    mpz_clear(temp);
  }
  static void eval(mpz_ptr z, double d, mpz_srcptr w)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_add(z, temp, w);
    mpz_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
  { mpq_add(q, r, s); }

  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_add(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_add(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_add(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_add(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, double d)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_add(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, double d, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_add(q, temp, r);
    mpq_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z)
  {
    mpq_set(q, r);
    mpz_addmul(mpq_numref(q), mpq_denref(q), z);
  }
  static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r)
  {
    mpq_set(q, r);
    mpz_addmul(mpq_numref(q), mpq_denref(q), z);
  }

  static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
  { mpf_add(f, g, h); }

  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_add_ui(f, g, l); }
  static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
  { mpf_add_ui(f, g, l); }
  static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
  {
    if (l >= 0)
      mpf_add_ui(f, g, l);
    else
      mpf_sub_ui(f, g, -l);
  }
  static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
  {
    if (l >= 0)
      mpf_add_ui(f, g, l);
    else
      mpf_sub_ui(f, g, -l);
  }
  static void eval(mpf_ptr f, mpf_srcptr g, double d)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_add(f, g, temp);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, double d, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_add(f, temp, g);
    mpf_clear(temp);
  }

#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mpfr_srcptr h, mp_rnd_t mode)
  { mpfr_add(f, g, h, mode); }

  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_add_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, unsigned long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  { mpfr_add_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, mpfr_srcptr g, signed long int l,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_add_ui(f, g, l, mode);
    else
      mpfr_sub_ui(f, g, -l, mode);
  }
  static void eval(mpfr_ptr f, signed long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_add_ui(f, g, l, mode);
    else
      mpfr_sub_ui(f, g, -l, mode);
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, double d, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_add(f, g, temp, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, double d, mpfr_srcptr g, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_add(f, temp, g, mode);
    mpfr_clear(temp);
  }
#endif
};

struct __gmp_binary_minus
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_sub(z, w, v); }

  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_sub_ui(z, w, l); }
  static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
  { mpz_ui_sub(z, l, w); }
  static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
  {
    if (l >= 0)
      mpz_sub_ui(z, w, l);
    else
      mpz_add_ui(z, w, -l);
  }
  static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
  {
    if (l >= 0)
      mpz_ui_sub(z, l, w);
    else
      {
        mpz_add_ui(z, w, -l);
        mpz_neg(z, z);
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, double d)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_sub(z, w, temp);
    mpz_clear(temp);
  }
  static void eval(mpz_ptr z, double d, mpz_srcptr w)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_sub(z, temp, w);
    mpz_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
  { mpq_sub(q, r, s); }

  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_sub(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_sub(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_sub(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_sub(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, double d)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_sub(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, double d, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_sub(q, temp, r);
    mpq_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z)
  {
    mpq_set(q, r);
    mpz_submul(mpq_numref(q), mpq_denref(q), z);
  }
  static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r)
  {
    mpq_neg(q, r);
    mpz_addmul(mpq_numref(q), mpq_denref(q), z);
  }

  static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
  { mpf_sub(f, g, h); }

  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_sub_ui(f, g, l); }
  static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
  { mpf_ui_sub(f, l, g); }
  static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
  {
    if (l >= 0)
      mpf_sub_ui(f, g, l);
    else
      mpf_add_ui(f, g, -l);
  }
  static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
  {
    if (l >= 0)
      mpf_sub_ui(f, g, l);
    else
      mpf_add_ui(f, g, -l);
    mpf_neg(f, f);
  }
  static void eval(mpf_ptr f, mpf_srcptr g, double d)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_sub(f, g, temp);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, double d, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_sub(f, temp, g);
    mpf_clear(temp);
  }

#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mpfr_srcptr h, mp_rnd_t mode)
  { mpfr_sub(f, g, h, mode); }

  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_sub_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, unsigned long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  { mpfr_ui_sub(f, l, g, mode); }
  static void eval(mpfr_ptr f, mpfr_srcptr g, signed long int l,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_sub_ui(f, g, l, mode);
    else
      mpfr_add_ui(f, g, -l, mode);
  }
  static void eval(mpfr_ptr f, signed long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_sub_ui(f, g, l, mode);
    else
      mpfr_add_ui(f, g, -l, mode);
    mpfr_neg(f, f, mode);
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, double d, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_sub(f, g, temp, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, double d, mpfr_srcptr g, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_sub(f, temp, g, mode);
    mpfr_clear(temp);
  }
#endif
};

struct __gmp_binary_multiplies
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_mul(z, w, v); }

  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_mul_ui(z, w, l); }
  static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
  { mpz_mul_ui(z, w, l); }
  static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
  {
    if (l >= 0)
      mpz_mul_ui(z, w, l);
    else
      {
        mpz_mul_ui(z, w, -l);
        mpz_neg(z, z);
      }
  }
  static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
  {
    if (l >= 0)
      mpz_mul_ui(z, w, l);
    else
      {
        mpz_mul_ui(z, w, -l);
        mpz_neg(z, z);
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, double d)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_mul(z, w, temp);
    mpz_clear(temp);
  }
  static void eval(mpz_ptr z, double d, mpz_srcptr w)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_mul(z, temp, w);
    mpz_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
  { mpq_mul(q, r, s); }

  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_mul(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_mul(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_mul(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_mul(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, double d)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_mul(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, double d, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_mul(q, temp, r);
    mpq_clear(temp);
  }

  static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
  { mpf_mul(f, g, h); }

  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_mul_ui(f, g, l); }
  static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
  { mpf_mul_ui(f, g, l); }
  static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
  {
    if (l >= 0)
      mpf_mul_ui(f, g, l);
    else
      {
        mpf_mul_ui(f, g, -l);
        mpf_neg(f, f);
      }
  }
  static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
  {
    if (l >= 0)
      mpf_mul_ui(f, g, l);
    else
      {
        mpf_mul_ui(f, g, -l);
        mpf_neg(f, f);
      }
  }
  static void eval(mpf_ptr f, mpf_srcptr g, double d)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_mul(f, g, temp);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, double d, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_mul(f, temp, g);
    mpf_clear(temp);
  }

#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mpfr_srcptr h, mp_rnd_t mode)
  { mpfr_mul(f, g, h, mode); }

  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_mul_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, unsigned long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  { mpfr_mul_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, mpfr_srcptr g, signed long int l,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_mul_ui(f, g, l, mode);
    else
      {
        mpfr_mul_ui(f, g, -l, mode);
        mpfr_neg(f, f, mode);
      }
  }
  static void eval(mpfr_ptr f, signed long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_mul_ui(f, g, l, mode);
    else
      {
        mpfr_mul_ui(f, g, -l, mode);
        mpfr_neg(f, f, mode);
      }
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, double d, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_mul(f, g, temp, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, double d, mpfr_srcptr g, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_mul(f, temp, g, mode);
    mpfr_clear(temp);
  }
#endif
};

struct __gmp_binary_divides
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_tdiv_q(z, w, v); }

  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_tdiv_q_ui(z, w, l); }
  static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
  {
    if (mpz_sgn(w) >= 0)
      {
        if (mpz_fits_ulong_p(w))
          mpz_set_ui(z, l / mpz_get_ui(w));
        else
          mpz_set_ui(z, 0);
      }
    else
      {
        mpz_neg(z, w);
        if (mpz_fits_ulong_p(z))
          {
            mpz_set_ui(z, l / mpz_get_ui(z));
            mpz_neg(z, z);
          }
        else
          mpz_set_ui(z, 0);
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
  {
    if (l >= 0)
      mpz_tdiv_q_ui(z, w, l);
    else
      {
        mpz_tdiv_q_ui(z, w, -l);
        mpz_neg(z, z);
      }
  }
  static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
  {
    if (mpz_fits_slong_p(w))
      mpz_set_si(z, l / mpz_get_si(w));
    else
      {
        /* if w is bigger than a long then the quotient must be zero, unless
           l==LONG_MIN and w==-LONG_MIN in which case the quotient is -1 */
        mpz_set_si (z, (mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? -1 : 0));
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, double d)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_tdiv_q(z, w, temp);
    mpz_clear(temp);
  }
  static void eval(mpz_ptr z, double d, mpz_srcptr w)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_tdiv_q(z, temp, w);
    mpz_clear(temp);
  }

  static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
  { mpq_div(q, r, s); }

  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_div(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_ui(temp, l, 1);
    mpq_div(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_div(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_si(temp, l, 1);
    mpq_div(q, temp, r);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, mpq_srcptr r, double d)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_div(q, r, temp);
    mpq_clear(temp);
  }
  static void eval(mpq_ptr q, double d, mpq_srcptr r)
  {
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    mpq_div(q, temp, r);
    mpq_clear(temp);
  }

  static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
  { mpf_div(f, g, h); }

  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_div_ui(f, g, l); }
  static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
  { mpf_ui_div(f, l, g); }
  static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
  {
    if (l >= 0)
      mpf_div_ui(f, g, l);
    else
      {
        mpf_div_ui(f, g, -l);
        mpf_neg(f, f);
      }
  }
  static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
  {
    if (l >= 0)
      mpf_ui_div(f, l, g);
    else
      {
        mpf_ui_div(f, -l, g);
        mpf_neg(f, f);
      }
  }
  static void eval(mpf_ptr f, mpf_srcptr g, double d)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_div(f, g, temp);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, double d, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, 8*sizeof(double));
    mpf_set_d(temp, d);
    mpf_div(f, temp, g);
    mpf_clear(temp);
  }

#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mpfr_srcptr h, mp_rnd_t mode)
  { mpfr_div(f, g, h, mode); }

  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_div_ui(f, g, l, mode); }
  static void eval(mpfr_ptr f, unsigned long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  { mpfr_ui_div(f, l, g, mode); }
  static void eval(mpfr_ptr f, mpfr_srcptr g, signed long int l,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_div_ui(f, g, l, mode);
    else
      {
        mpfr_div_ui(f, g, -l, mode);
        mpfr_neg(f, f, mode);
      }
  }
  static void eval(mpfr_ptr f, signed long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    if (l >= 0)
      mpfr_ui_div(f, l, g, mode);
    else
      {
        mpfr_ui_div(f, -l, g, mode);
        mpfr_neg(f, f, mode);
      }
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, double d, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_div(f, g, temp, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, double d, mpfr_srcptr g, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, mode);
    mpfr_div(f, temp, g, mode);
    mpfr_clear(temp);
  }
#endif
};

struct __gmp_binary_modulus
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_tdiv_r(z, w, v); }

  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_tdiv_r_ui(z, w, l); }
  static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
  {
    if (mpz_sgn(w) >= 0)
      {
        if (mpz_fits_ulong_p(w))
          mpz_set_ui(z, l % mpz_get_ui(w));
        else
          mpz_set_ui(z, l);
      }
    else
      {
        mpz_neg(z, w);
        if (mpz_fits_ulong_p(z))
          mpz_set_ui(z, l % mpz_get_ui(z));
        else
          mpz_set_ui(z, l);
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
  {
    mpz_tdiv_r_ui (z, w, (l >= 0 ? l : -l));
  }
  static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
  {
    if (mpz_fits_slong_p(w))
      mpz_set_si(z, l % mpz_get_si(w));
    else
      {
        /* if w is bigger than a long then the remainder is l unchanged,
           unless l==LONG_MIN and w==-LONG_MIN in which case it's 0 */
        mpz_set_si (z, mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? 0 : l);
      }
  }
  static void eval(mpz_ptr z, mpz_srcptr w, double d)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_tdiv_r(z, w, temp);
    mpz_clear(temp);
  }
  static void eval(mpz_ptr z, double d, mpz_srcptr w)
  {
    mpz_t temp;
    mpz_init_set_d(temp, d);
    mpz_tdiv_r(z, temp, w);
    mpz_clear(temp);
  }
};

struct __gmp_binary_and
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_and(z, w, v); }
};

struct __gmp_binary_ior
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_ior(z, w, v); }
};

struct __gmp_binary_xor
{
  static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
  { mpz_xor(z, w, v); }
};

struct __gmp_binary_lshift
{
  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_mul_2exp(z, w, l); }
  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  { mpq_mul_2exp(q, r, l); }
  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_mul_2exp(f, g, l); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_mul_2exp(f, g, l, mode); }
#endif
};

struct __gmp_binary_rshift
{
  static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
  { mpz_tdiv_q_2exp(z, w, l); }
  static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
  { mpq_div_2exp(q, r, l); }
  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  { mpf_div_2exp(f, g, l); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  { mpfr_div_2exp(f, g, l, mode); }
#endif
};

struct __gmp_binary_equal
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) == 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) == 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) == 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) == 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) == 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) == 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) == 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r)
  { return mpq_equal(q, r) != 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) == 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) == 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) == 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) == 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_equal(q, temp) != 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_equal(temp, q) != 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) == 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) == 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) == 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) == 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) == 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) == 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) == 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) == 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) == 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) == 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) == 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) == 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) == 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) == 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) == 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) == 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_binary_not_equal
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) != 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) != 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) != 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) != 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) != 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) != 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) != 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r)
  { return mpq_equal(q, r) == 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) != 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) != 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) != 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) != 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_equal(q, temp) == 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_equal(temp, q) == 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) != 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) != 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) != 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) != 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) != 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) != 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) != 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) != 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) != 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) != 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) != 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) != 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) != 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) != 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) != 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) != 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_binary_less
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) < 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) < 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) > 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) < 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) > 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) < 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) > 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) < 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) < 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) > 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) < 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) > 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(q, temp) < 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(temp, q) < 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) < 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) < 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) > 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) < 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) > 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) < 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) > 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) < 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) < 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) > 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) < 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) > 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) > 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) < 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) < 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) < 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_binary_less_equal
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) <= 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) <= 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) >= 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) <= 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) >= 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) <= 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) >= 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) <= 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) <= 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) >= 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) <= 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) >= 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(q, temp) <= 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(temp, q) <= 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) <= 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) <= 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) >= 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) <= 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) >= 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) <= 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) >= 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) <= 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) <= 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) >= 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) <= 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) >= 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) >= 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) <= 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) <= 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) <= 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_binary_greater
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) > 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) > 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) < 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) > 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) < 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) > 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) < 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) > 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) > 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) < 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) > 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) < 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(q, temp) > 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(temp, q) > 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) > 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) > 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) < 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) > 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) < 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) > 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) < 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) > 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) > 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) < 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) > 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) < 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) < 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) > 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) > 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) > 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_binary_greater_equal
{
  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) >= 0; }

  static bool eval(mpz_srcptr z, unsigned long int l)
  { return mpz_cmp_ui(z, l) >= 0; }
  static bool eval(unsigned long int l, mpz_srcptr z)
  { return mpz_cmp_ui(z, l) <= 0; }
  static bool eval(mpz_srcptr z, signed long int l)
  { return mpz_cmp_si(z, l) >= 0; }
  static bool eval(signed long int l, mpz_srcptr z)
  { return mpz_cmp_si(z, l) <= 0; }
  static bool eval(mpz_srcptr z, double d)
  { return mpz_cmp_d(z, d) >= 0; }
  static bool eval(double d, mpz_srcptr z)
  { return mpz_cmp_d(z, d) <= 0; }

  static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) >= 0; }

  static bool eval(mpq_srcptr q, unsigned long int l)
  { return mpq_cmp_ui(q, l, 1) >= 0; }
  static bool eval(unsigned long int l, mpq_srcptr q)
  { return mpq_cmp_ui(q, l, 1) <= 0; }
  static bool eval(mpq_srcptr q, signed long int l)
  { return mpq_cmp_si(q, l, 1) >= 0; }
  static bool eval(signed long int l, mpq_srcptr q)
  { return mpq_cmp_si(q, l, 1) <= 0; }
  static bool eval(mpq_srcptr q, double d)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(q, temp) >= 0);
    mpq_clear(temp);
    return b;
  }
  static bool eval(double d, mpq_srcptr q)
  {
    bool b;
    mpq_t temp;
    mpq_init(temp);
    mpq_set_d(temp, d);
    b = (mpq_cmp(temp, q) >= 0);
    mpq_clear(temp);
    return b;
  }

  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) >= 0; }

  static bool eval(mpf_srcptr f, unsigned long int l)
  { return mpf_cmp_ui(f, l) >= 0; }
  static bool eval(unsigned long int l, mpf_srcptr f)
  { return mpf_cmp_ui(f, l) <= 0; }
  static bool eval(mpf_srcptr f, signed long int l)
  { return mpf_cmp_si(f, l) >= 0; }
  static bool eval(signed long int l, mpf_srcptr f)
  { return mpf_cmp_si(f, l) <= 0; }
  static bool eval(mpf_srcptr f, double d)
  { return mpf_cmp_d(f, d) >= 0; }
  static bool eval(double d, mpf_srcptr f)
  { return mpf_cmp_d(f, d) <= 0; }

#ifdef __MPFR_H
  static bool eval(mpfr_srcptr f, mpfr_srcptr g)
  { return mpfr_cmp(f, g) >= 0; }

  static bool eval(mpfr_srcptr f, unsigned long int l)
  { return mpfr_cmp_ui(f, l) >= 0; }
  static bool eval(unsigned long int l, mpfr_srcptr f)
  { return mpfr_cmp_ui(f, l) <= 0; }
  static bool eval(mpfr_srcptr f, signed long int l)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) >= 0;
        else
          return true;
      }
    else
      {
        if (l >= 0)
          return false;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) <= 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(signed long int l, mpfr_srcptr f)
  {
    if (mpfr_sgn(f) >= 0)
      {
        if (l >= 0)
          return mpfr_cmp_ui(f, l) <= 0;
        else
          return false;
      }
    else
      {
        if (l >= 0)
          return true;
        else
          {
            bool b;
            mpfr_t temp;
            mpfr_init2(temp, mpfr_get_prec(f));
            mpfr_neg(temp, f, __gmp_default_rounding_mode);
            b = (mpfr_cmp_ui(temp, -l) >= 0);
            mpfr_clear(temp);
            return b;
          }
      }
  }
  static bool eval(mpfr_srcptr f, double d)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(f, temp) >= 0);
    mpfr_clear(temp);
    return b;
  }
  static bool eval(double d, mpfr_srcptr f)
  {
    bool b;
    mpfr_t temp;
    mpfr_init2(temp, 8*sizeof(double));
    mpfr_set_d(temp, d, __gmp_default_rounding_mode);
    b = (mpfr_cmp(temp, f) >= 0);
    mpfr_clear(temp);
    return b;
  }
#endif
};

struct __gmp_unary_increment
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_add_ui(z, w, 1); }
  static void eval(mpq_ptr q, mpq_srcptr r)
  { mpz_add(mpq_numref(q), mpq_numref(r), mpq_denref(r)); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_add_ui(f, g, 1); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_add_ui(f, g, 1, mode); }
#endif
};

struct __gmp_unary_decrement
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_sub_ui(z, w, 1); }
  static void eval(mpq_ptr q, mpq_srcptr r)
  { mpz_sub(mpq_numref(q), mpq_numref(r), mpq_denref(r)); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_sub_ui(f, g, 1); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_sub_ui(f, g, 1, mode); }
#endif
};

struct __gmp_abs_function
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_abs(z, w); }
  static void eval(mpq_ptr q, mpq_srcptr r) { mpq_abs(q, r); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_abs(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_abs(f, g, mode); }
#endif
};

struct __gmp_trunc_function
{
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_trunc(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t) { mpfr_trunc(f, g); }
#endif
};

struct __gmp_floor_function
{
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_floor(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t) { mpfr_floor(f, g); }
#endif
};

struct __gmp_ceil_function
{
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_ceil(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t) { mpfr_ceil(f, g); }
#endif
};

struct __gmp_sqrt_function
{
  static void eval(mpz_ptr z, mpz_srcptr w) { mpz_sqrt(z, w); }
  static void eval(mpf_ptr f, mpf_srcptr g) { mpf_sqrt(f, g); }
#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mp_rnd_t mode)
  { mpfr_sqrt(f, g, mode); }
#endif
};

struct __gmp_hypot_function
{
  static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_mul(f, h, h);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }

  static void eval(mpf_ptr f, mpf_srcptr g, unsigned long int l)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_ui(f, l);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_ui(f, l);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_si(f, l);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_si(f, l);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, mpf_srcptr g, double d)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_d(f, d);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }
  static void eval(mpf_ptr f, double d, mpf_srcptr g)
  {
    mpf_t temp;
    mpf_init2(temp, mpf_get_prec(f));
    mpf_mul(temp, g, g);
    mpf_set_d(f, d);
    mpf_mul(f, f, f);
    mpf_add(f, f, temp);
    mpf_sqrt(f, f);
    mpf_clear(temp);
  }

#ifdef __MPFR_H
  static void eval(mpfr_ptr f, mpfr_srcptr g, mpfr_srcptr h, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_mul(f, h, h, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }

  static void eval(mpfr_ptr f, mpfr_srcptr g, unsigned long int l,
                   mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_ui(f, l, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, unsigned long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_ui(f, l, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, signed long int l,
                   mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_si(f, l, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, signed long int l, mpfr_srcptr g,
                   mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_si(f, l, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, mpfr_srcptr g, double d, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_d(f, d, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
  static void eval(mpfr_ptr f, double d, mpfr_srcptr g, mp_rnd_t mode)
  {
    mpfr_t temp;
    mpfr_init2(temp, mpfr_get_prec(f));
    mpfr_mul(temp, g, g, mode);
    mpfr_set_d(f, d, mode);
    mpfr_mul(f, f, f, mode);
    mpfr_add(f, f, temp, mode);
    mpfr_sqrt(f, f, mode);
    mpfr_clear(temp);
  }
#endif
};

struct __gmp_sgn_function
{
  static int eval(mpz_srcptr z) { return mpz_sgn(z); }
  static int eval(mpq_srcptr q) { return mpq_sgn(q); }
  static int eval(mpf_srcptr f) { return mpf_sgn(f); }
#ifdef __MPFR_H
  static int eval(mpfr_srcptr f) { return mpfr_cmp_ui(f, 0); }
#endif
};

struct __gmp_cmp_function
{
  static int eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w); }
  static int eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r); }
  static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); }
#ifdef __MPFR_H
  static int eval(mpfr_srcptr f, mpfr_srcptr g) { return mpfr_cmp(f, g); }
#endif
};

struct __gmp_rand_function
{
  static void eval(mpz_ptr z, gmp_randstate_t s, unsigned long int l)
  { mpz_urandomb(z, s, l); }
  static void eval(mpz_ptr z, gmp_randstate_t s, mpz_srcptr w)
  { mpz_urandomm(z, s, w); }
  static void eval(mpf_ptr f, gmp_randstate_t s, unsigned long int prec)
  { mpf_urandomb(f, s, prec); }
};


/**************** Auxiliary classes ****************/

/* this is the same as gmp_allocated_string in gmp-impl.h
   since gmp-impl.h is not publicly available, I redefine it here
   I use a different name to avoid possible clashes */
struct __gmp_alloc_cstring
{
  char *str;
  __gmp_alloc_cstring(char *s) { str = s; }
  ~__gmp_alloc_cstring() { __gmp_free_func(str, strlen(str)+1); }
};


template <class T, class U>
class __gmp_expr;

template <class T>
struct __gmp_resolve_ref
{
  typedef T ref_type;
};

template <class T, class U>
struct __gmp_resolve_ref<__gmp_expr<T, U> >
{
  typedef const __gmp_expr<T, U> & ref_type;
};

template <class T, class Op>
struct __gmp_unary_expr
{
  typename __gmp_resolve_ref<T>::ref_type val;
  __gmp_unary_expr(const T &v) : val(v) { }
private:
  __gmp_unary_expr();
};

template <class T, class U, class Op>
struct __gmp_binary_expr
{
  typename __gmp_resolve_ref<T>::ref_type val1;
  typename __gmp_resolve_ref<U>::ref_type val2;
  __gmp_binary_expr(const T &v1, const U &v2) : val1(v1), val2(v2) { }
private:
  __gmp_binary_expr();
};


class __gmpz_value { };
class __gmpzref_value { };
class __gmpq_value { };
class __gmpf_value { };


template <class T, class U>
void __gmp_set_expr(mpz_ptr, const __gmp_expr<T, U> &);
template <class T, class U>
void __gmp_set_expr(mpq_ptr, const __gmp_expr<T, U> &);
template <class T, class U>
void __gmp_set_expr(mpf_ptr, const __gmp_expr<T, U> &);


/**************** Macros for in-class declarations ****************/
/* This is just repetitive code that is easier to maintain if it's written
   only once */

#define __GMPZZ_DECLARE_COMPOUND_OPERATOR(fun)                            \
  template <class T, class U>                                             \
  __gmp_expr<__gmpz_value, __gmpz_value> & fun(const __gmp_expr<T, U> &);

#define __GMPZN_DECLARE_COMPOUND_OPERATOR(fun) \
  __gmp_expr & fun(signed char);               \
  __gmp_expr & fun(unsigned char);             \
  __gmp_expr & fun(signed int);                \
  __gmp_expr & fun(unsigned int);              \
  __gmp_expr & fun(signed short int);          \
  __gmp_expr & fun(unsigned short int);        \
  __gmp_expr & fun(signed long int);           \
  __gmp_expr & fun(unsigned long int);         \
  __gmp_expr & fun(float);                     \
  __gmp_expr & fun(double);                    \
  __gmp_expr & fun(long double);

#define __GMPZ_DECLARE_COMPOUND_OPERATOR(fun) \
__GMPZZ_DECLARE_COMPOUND_OPERATOR(fun)        \
__GMPZN_DECLARE_COMPOUND_OPERATOR(fun)

#define __GMPZ_DECLARE_COMPOUND_OPERATOR_UI(fun) \
  __gmp_expr & fun(unsigned long int);

#define __GMPZ_DECLARE_INCREMENT_OPERATOR(fun) \
  inline __gmp_expr & fun();                   \
  inline __gmp_expr fun(int);

#define __GMPZRR_DECLARE_COMPOUND_OPERATOR(fun)                              \
  template <class T, class U>                                                \
  __gmp_expr<__gmpz_value, __gmpzref_value> & fun(const __gmp_expr<T, U> &);

#define __GMPZRN_DECLARE_COMPOUND_OPERATOR(fun) \
  __gmp_expr & fun(signed char);                \
  __gmp_expr & fun(unsigned char);              \
  __gmp_expr & fun(signed int);                 \
  __gmp_expr & fun(unsigned int);               \
  __gmp_expr & fun(signed short int);           \
  __gmp_expr & fun(unsigned short int);         \
  __gmp_expr & fun(signed long int);            \
  __gmp_expr & fun(unsigned long int);          \
  __gmp_expr & fun(float);                      \
  __gmp_expr & fun(double);                     \
  __gmp_expr & fun(long double);

#define __GMPZR_DECLARE_COMPOUND_OPERATOR(fun) \
__GMPZRR_DECLARE_COMPOUND_OPERATOR(fun)        \
__GMPZRN_DECLARE_COMPOUND_OPERATOR(fun)

#define __GMPZR_DECLARE_COMPOUND_OPERATOR_UI(fun) \
  __gmp_expr & fun(unsigned long int);

#define __GMPZR_DECLARE_INCREMENT_OPERATOR(fun) \
  inline __gmp_expr & fun();                    \
  inline mpz_class fun(int);

#define __GMPQQ_DECLARE_COMPOUND_OPERATOR(fun)                            \
  template <class T, class U>                                             \
  __gmp_expr<__gmpq_value, __gmpq_value> & fun(const __gmp_expr<T, U> &);

#define __GMPQN_DECLARE_COMPOUND_OPERATOR(fun) \
  __gmp_expr & fun(signed char);               \
  __gmp_expr & fun(unsigned char);             \
  __gmp_expr & fun(signed int);                \
  __gmp_expr & fun(unsigned int);              \
  __gmp_expr & fun(signed short int);          \
  __gmp_expr & fun(unsigned short int);        \
  __gmp_expr & fun(signed long int);           \
  __gmp_expr & fun(unsigned long int);         \
  __gmp_expr & fun(float);                     \
  __gmp_expr & fun(double);                    \
  __gmp_expr & fun(long double);

#define __GMPQ_DECLARE_COMPOUND_OPERATOR(fun) \
__GMPQQ_DECLARE_COMPOUND_OPERATOR(fun)        \
__GMPQN_DECLARE_COMPOUND_OPERATOR(fun)

#define __GMPQ_DECLARE_COMPOUND_OPERATOR_UI(fun) \
  __gmp_expr & fun(unsigned long int);

#define __GMPQ_DECLARE_INCREMENT_OPERATOR(fun) \
  inline __gmp_expr & fun();                   \
  inline __gmp_expr fun(int);

#define __GMPFF_DECLARE_COMPOUND_OPERATOR(fun)                            \
  template <class T, class U>                                             \
  __gmp_expr<__gmpf_value, __gmpf_value> & fun(const __gmp_expr<T, U> &);

#define __GMPFN_DECLARE_COMPOUND_OPERATOR(fun) \
  __gmp_expr & fun(signed char);               \
  __gmp_expr & fun(unsigned char);             \
  __gmp_expr & fun(signed int);                \
  __gmp_expr & fun(unsigned int);              \
  __gmp_expr & fun(signed short int);          \
  __gmp_expr & fun(unsigned short int);        \
  __gmp_expr & fun(signed long int);           \
  __gmp_expr & fun(unsigned long int);         \
  __gmp_expr & fun(float);                     \
  __gmp_expr & fun(double);                    \
  __gmp_expr & fun(long double);

#define __GMPF_DECLARE_COMPOUND_OPERATOR(fun) \
__GMPFF_DECLARE_COMPOUND_OPERATOR(fun)        \
__GMPFN_DECLARE_COMPOUND_OPERATOR(fun)

#define __GMPF_DECLARE_COMPOUND_OPERATOR_UI(fun) \
  __gmp_expr & fun(unsigned long int);

#define __GMPF_DECLARE_INCREMENT_OPERATOR(fun) \
  inline __gmp_expr & fun();                   \
  inline __gmp_expr fun(int);


/**************** mpz_class -- wrapper for mpz_t ****************/

template <>
class __gmp_expr<__gmpz_value, __gmpz_value>
{
private:
  mpz_t mp;
public:
  unsigned long int get_prec() const { return mpf_get_default_prec(); }

  // constructors and destructor
  __gmp_expr() { mpz_init(mp); }

  __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); }
  template <class T, class U>
  __gmp_expr(const __gmp_expr<T, U> &expr)
  { mpz_init(mp); __gmp_set_expr(mp, expr); }

  __gmp_expr(signed char c) { mpz_init_set_si(mp, c); }
  __gmp_expr(unsigned char c) { mpz_init_set_ui(mp, c); }

  __gmp_expr(signed int i) { mpz_init_set_si(mp, i); }
  __gmp_expr(unsigned int i) { mpz_init_set_ui(mp, i); }

  __gmp_expr(signed short int s) { mpz_init_set_si(mp, s); }
  __gmp_expr(unsigned short int s) { mpz_init_set_ui(mp, s); }

  __gmp_expr(signed long int l) { mpz_init_set_si(mp, l); }
  __gmp_expr(unsigned long int l) { mpz_init_set_ui(mp, l); }

  __gmp_expr(float f) { mpz_init_set_d(mp, f); }
  __gmp_expr(double d) { mpz_init_set_d(mp, d); }
  // __gmp_expr(long double ld) { mpz_init_set_d(mp, ld); }

  explicit __gmp_expr(const char *s)

  { mpz_init_set_str(mp, s, 0); }
  __gmp_expr(const char *s, int base)
  { mpz_init_set_str(mp, s, base); }
  explicit __gmp_expr(const std::string &s)
  { mpz_init_set_str(mp, s.c_str(), 0); }
  __gmp_expr(const std::string &s, int base)
  { mpz_init_set_str(mp, s.c_str(), base); }

  explicit __gmp_expr(mpz_srcptr z) { mpz_init_set(mp, z); }

  ~__gmp_expr() { mpz_clear(mp); }

  // assignment operators
  __gmp_expr & operator=(const __gmp_expr &z)
  { mpz_set(mp, z.mp); return *this; }
  template <class T, class U>
  __gmp_expr<__gmpz_value, __gmpz_value> & operator=
  (const __gmp_expr<T, U> &expr)
  { __gmp_set_expr(mp, expr); return *this; }

  __gmp_expr & operator=(signed char c) { mpz_set_si(mp, c); return *this; }
  __gmp_expr & operator=(unsigned char c) { mpz_set_ui(mp, c); return *this; }

  __gmp_expr & operator=(signed int i) { mpz_set_si(mp, i); return *this; }
  __gmp_expr & operator=(unsigned int i) { mpz_set_ui(mp, i); return *this; }

  __gmp_expr & operator=(signed short int s)
  { mpz_set_si(mp, s); return *this; }
  __gmp_expr & operator=(unsigned short int s)
  { mpz_set_ui(mp, s); return *this; }

  __gmp_expr & operator=(signed long int l)
  { mpz_set_si(mp, l); return *this; }
  __gmp_expr & operator=(unsigned long int l)
  { mpz_set_ui(mp, l); return *this; }

  __gmp_expr & operator=(float f) { mpz_set_d(mp, f); return *this; }
  __gmp_expr & operator=(double d) { mpz_set_d(mp, d); return *this; }
  /*
  __gmp_expr & operator=(long double ld) { mpz_set_ld(mp, ld); return *this; }
  */

  __gmp_expr & operator=(const char *s)
  { mpz_set_str(mp, s, 0); return *this; }
  __gmp_expr & operator=(const std::string &s)
  { mpz_set_str(mp, s.c_str(), 0); return *this; }

  // string input/output functions
  int set_str(const std::string &s, int base)
  { return mpz_set_str(mp, s.c_str(), base); }
  std::string get_str(int base = 10) const
  {
    __gmp_alloc_cstring temp(mpz_get_str(0, base, mp));
    return std::string(temp.str);
  }

  // conversion functions
  mpz_srcptr get_mpz_t() const { return mp; }
  mpz_ptr get_mpz_t() { return mp; }

  signed long int get_si() const { return mpz_get_si(mp); }
  unsigned long int get_ui() const { return mpz_get_ui(mp); }
  double get_d() const { return mpz_get_d(mp); } // should be long double

  // bool fits_schar_p() const { return mpz_fits_schar_p(mp); }
  // bool fits_uchar_p() const { return mpz_fits_uchar_p(mp); }
  bool fits_sint_p() const { return mpz_fits_sint_p(mp); }
  bool fits_uint_p() const { return mpz_fits_uint_p(mp); }
  bool fits_sshort_p() const { return mpz_fits_sshort_p(mp); }
  bool fits_ushort_p() const { return mpz_fits_ushort_p(mp); }
  bool fits_slong_p() const { return mpz_fits_slong_p(mp); }
  bool fits_ulong_p() const { return mpz_fits_ulong_p(mp); }
  // bool fits_float_p() const { return mpz_fits_float_p(mp); }
  // bool fits_double_p() const { return mpz_fits_double_p(mp); }
  // bool fits_ldouble_p() const { return mpz_fits_ldouble_p(mp); }

  // member operators
  __GMPZ_DECLARE_COMPOUND_OPERATOR(operator+=)
  __GMPZ_DECLARE_COMPOUND_OPERATOR(operator-=)
  __GMPZ_DECLARE_COMPOUND_OPERATOR(operator*=)
  __GMPZ_DECLARE_COMPOUND_OPERATOR(operator/=)
  __GMPZ_DECLARE_COMPOUND_OPERATOR(operator%=)

  __GMPZZ_DECLARE_COMPOUND_OPERATOR(operator&=)
  __GMPZZ_DECLARE_COMPOUND_OPERATOR(operator|=)
  __GMPZZ_DECLARE_COMPOUND_OPERATOR(operator^=)

  __GMPZ_DECLARE_COMPOUND_OPERATOR_UI(operator<<=)
  __GMPZ_DECLARE_COMPOUND_OPERATOR_UI(operator>>=)

  __GMPZ_DECLARE_INCREMENT_OPERATOR(operator++)
  __GMPZ_DECLARE_INCREMENT_OPERATOR(operator--)
};

typedef __gmp_expr<__gmpz_value, __gmpz_value> mpz_class;


inline std::ostream & operator<<(std::ostream &o, const mpz_class &z)
{
  return o << z.get_mpz_t();
}

template <class T>
inline std::ostream & operator<<
(std::ostream &o, const __gmp_expr<__gmpz_value, T> &expr)
{
  mpz_class temp(expr);
  return o << temp.get_mpz_t();
}

inline std::istream & operator>>(std::istream &i, mpz_class &z)
{
  return i >> z.get_mpz_t();
}


/**************** mpz_classref -- num/den of mpq_t ****************/

template <>
class __gmp_expr<__gmpz_value, __gmpzref_value>
{
  friend class __gmp_expr<__gmpq_value, __gmpq_value>;
private:
  mpz_ptr ref;

  __gmp_expr();
  // __gmp_expr(const __gmp_expr &);
  __gmp_expr(mpz_ptr z) : ref(z) { }
  __gmp_expr(mpz_srcptr z) : ref((mpz_ptr) z) { }
public:
  unsigned long int get_prec() const { return mpf_get_default_prec(); }

  // assignment operators
  __gmp_expr & operator=(const __gmp_expr &z)
  { mpz_set(ref, z.ref); return *this; }
  __gmp_expr & operator=(const mpz_class &z)
  { mpz_set(ref, z.get_mpz_t()); return *this; }
  template <class T, class U>
  __gmp_expr<__gmpz_value, __gmpzref_value> & operator=
  (const __gmp_expr<T, U> &expr)
  { __gmp_set_expr(ref, expr); return *this; }

  __gmp_expr & operator=(signed char c) { mpz_set_si(ref, c); return *this; }
  __gmp_expr & operator=(unsigned char c)
  { mpz_set_ui(ref, c); return *this; }

  __gmp_expr & operator=(signed int i) { mpz_set_si(ref, i); return *this; }
  __gmp_expr & operator=(unsigned int i) { mpz_set_ui(ref, i); return *this; }

  __gmp_expr & operator=(signed short int s)
  { mpz_set_si(ref, s); return *this; }
  __gmp_expr & operator=(unsigned short int s)
  { mpz_set_ui(ref, s); return *this; }

  __gmp_expr & operator=(signed long int l)
  { mpz_set_si(ref, l); return *this; }
  __gmp_expr & operator=(unsigned long int l)
  { mpz_set_ui(ref, l); return *this; }

  __gmp_expr & operator=(float f) { mpz_set_d(ref, f); return *this; }
  __gmp_expr & operator=(double d) { mpz_set_d(ref, d); return *this; }
  /*
  __gmp_expr & operator=(long double ld)
  { mpz_set_ld(ref, ld); return *this; }
  */

  __gmp_expr & operator=(const char *s)
  { mpz_set_str(ref, s, 0); return *this; }
  __gmp_expr & operator=(const std::string &s)
  { mpz_set_str(ref, s.c_str(), 0); return *this; }

  // string input/output functions
  int set_str(const std::string &s, int base)
  { return mpz_set_str(ref, s.c_str(), base); }
  std::string get_str(int base = 10) const
  {
    __gmp_alloc_cstring temp(mpz_get_str(0, base, ref));
    return std::string(temp.str);
  }

  // conversion functions
  mpz_srcptr get_mpz_t() const { return ref; }
  mpz_ptr get_mpz_t() { return ref; }

  signed long int get_si() const { return mpz_get_si(ref); }
  unsigned long int get_ui() const { return mpz_get_ui(ref); }
  double get_d() const { return mpz_get_d(ref); } // should be long double

  // bool fits_bool_p() const { return mpz_fits_bool_p(ref); }
  // bool fits_schar_p() const { return mpz_fits_schar_p(ref); }
  // bool fits_uchar_p() const { return mpz_fits_uchar_p(ref); }
  bool fits_sint_p() const { return mpz_fits_sint_p(ref); }
  bool fits_uint_p() const { return mpz_fits_uint_p(ref); }
  bool fits_sshort_p() const { return mpz_fits_sshort_p(ref); }
  bool fits_ushort_p() const { return mpz_fits_ushort_p(ref); }
  bool fits_slong_p() const { return mpz_fits_slong_p(ref); }
  bool fits_ulong_p() const { return mpz_fits_ulong_p(ref); }
  // bool fits_float_p() const { return mpz_fits_float_p(ref); }
  // bool fits_double_p() const { return mpz_fits_double_p(ref); }
  // bool fits_ldouble_p() const { return mpz_fits_ldouble_p(ref); }

  // member operators
  __GMPZR_DECLARE_COMPOUND_OPERATOR(operator+=)
  __GMPZR_DECLARE_COMPOUND_OPERATOR(operator-=)
  __GMPZR_DECLARE_COMPOUND_OPERATOR(operator*=)
  __GMPZR_DECLARE_COMPOUND_OPERATOR(operator/=)
  __GMPZR_DECLARE_COMPOUND_OPERATOR(operator%=)

  __GMPZRR_DECLARE_COMPOUND_OPERATOR(operator&=)
  __GMPZRR_DECLARE_COMPOUND_OPERATOR(operator|=)
  __GMPZRR_DECLARE_COMPOUND_OPERATOR(operator^=)

  __GMPZR_DECLARE_COMPOUND_OPERATOR_UI(operator<<=)
  __GMPZR_DECLARE_COMPOUND_OPERATOR_UI(operator>>=)

  __GMPZR_DECLARE_INCREMENT_OPERATOR(operator++)
  __GMPZR_DECLARE_INCREMENT_OPERATOR(operator--)
};

typedef __gmp_expr<__gmpz_value, __gmpzref_value> mpz_classref;


inline std::ostream & operator<<(std::ostream &o, const mpz_classref &z)
{
  return o << z.get_mpz_t();
}

inline std::istream & operator>>(std::istream &i, mpz_classref &z)
{
  return i >> z.get_mpz_t();
}

/**************** mpq_class -- wrapper for mpq_t ****************/

template <>
class __gmp_expr<__gmpq_value, __gmpq_value>
{
private:
  mpq_t mp;
public:
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
  void canonicalize() { mpq_canonicalize(mp); }

  // constructors and destructor
  __gmp_expr() { mpq_init(mp); }

  __gmp_expr(const __gmp_expr &q) { mpq_init(mp); mpq_set(mp, q.mp); }
  template <class T, class U>
  __gmp_expr(const __gmp_expr<T, U> &expr)
  { mpq_init(mp); __gmp_set_expr(mp, expr); }

  __gmp_expr(signed char c) { mpq_init(mp); mpq_set_si(mp, c, 1); }
  __gmp_expr(unsigned char c) { mpq_init(mp); mpq_set_ui(mp, c, 1); }

  __gmp_expr(signed int i) { mpq_init(mp); mpq_set_si(mp, i, 1); }
  __gmp_expr(unsigned int i) { mpq_init(mp); mpq_set_ui(mp, i, 1); }

  __gmp_expr(signed short int s) { mpq_init(mp); mpq_set_si(mp, s, 1); }
  __gmp_expr(unsigned short int s) { mpq_init(mp); mpq_set_ui(mp, s, 1); }

  __gmp_expr(signed long int l) { mpq_init(mp); mpq_set_si(mp, l, 1); }
  __gmp_expr(unsigned long int l) { mpq_init(mp); mpq_set_ui(mp, l, 1); }

  __gmp_expr(float f) { mpq_init(mp); mpq_set_d(mp, f); }
  __gmp_expr(double d) { mpq_init(mp); mpq_set_d(mp, d); }
  // __gmp_expr(long double ld) { mpq_init(mp); mpq_set_ld(mp, ld); }

  explicit __gmp_expr(const char *s)
  { mpq_init(mp); mpq_set_str(mp, s, 0); }
  __gmp_expr(const char *s, unsigned long int base)
  { mpq_init(mp); mpq_set_str(mp, s, base); }
  explicit __gmp_expr(const std::string &s)
  { mpq_init(mp); mpq_set_str(mp, s.c_str(), 0); }
  __gmp_expr(const std::string &s, unsigned long int base)
  { mpq_init(mp); mpq_set_str(mp, s.c_str(), base); }

  explicit __gmp_expr(mpq_srcptr q) { mpq_init(mp); mpq_set(mp, q); }

  __gmp_expr(const mpz_class &num, const mpz_class &den)
  {
    mpq_init(mp);
    mpz_set(mpq_numref(mp), num.get_mpz_t());
    mpz_set(mpq_denref(mp), den.get_mpz_t());
  }
  // this is defined later (after __gmpz_temp)
  template <class T, class U>
  __gmp_expr(const __gmp_expr<__gmpz_value, T> &,
             const __gmp_expr<__gmpz_value, U> &);

  ~__gmp_expr() { mpq_clear(mp); }

  // assignment operators
  __gmp_expr & operator=(const __gmp_expr &q)
  { mpq_set(mp, q.mp); return *this; }
  template <class T, class U>
  __gmp_expr<__gmpq_value, __gmpq_value> & operator=
  (const __gmp_expr<T, U> &expr)
  { __gmp_set_expr(mp, expr); return *this; }

  __gmp_expr & operator=(signed char c)
  { mpq_set_si(mp, c, 1); return *this; }
  __gmp_expr & operator=(unsigned char c)
  { mpq_set_ui(mp, c, 1); return *this; }

  __gmp_expr & operator=(signed int i) { mpq_set_si(mp, i, 1); return *this; }
  __gmp_expr & operator=(unsigned int i)
  { mpq_set_ui(mp, i, 1); return *this; }

  __gmp_expr & operator=(signed short int s)
  { mpq_set_si(mp, s, 1); return *this; }
  __gmp_expr & operator=(unsigned short int s)
  { mpq_set_ui(mp, s, 1); return *this; }

  __gmp_expr & operator=(signed long int l)
  { mpq_set_si(mp, l, 1); return *this; }
  __gmp_expr & operator=(unsigned long int l)
  { mpq_set_ui(mp, l, 1); return *this; }

  __gmp_expr & operator=(float f) { mpq_set_d(mp, f); return *this; }
  __gmp_expr & operator=(double d) { mpq_set_d(mp, d); return *this; }
  /*
  __gmp_expr & operator=(long double ld) { mpq_set_ld(mp, ld); return *this; }
  */

  __gmp_expr & operator=(const char *s)
  { mpq_set_str(mp, s, 0); return *this; }
  __gmp_expr & operator=(const std::string &s)
  { mpq_set_str(mp, s.c_str(), 0); return *this; }

  // string input/output functions
  int set_str(const std::string &s, int base)
  { return mpq_set_str(mp, s.c_str(), base); }
  std::string get_str(int base = 10) const
  {
    __gmp_alloc_cstring temp(mpq_get_str(0, base, mp));
    return std::string(temp.str);
  }

  // conversion functions

  // casting a reference to an mpz_t to mpz_class & is a dirty hack,
  // but works because the internal representation of mpz_class is
  // exactly an mpz_t
  const mpz_class & get_num() const
  { return reinterpret_cast<const mpz_class &>(*mpq_numref(mp)); }
  mpz_class & get_num()
  { return reinterpret_cast<mpz_class &>(*mpq_numref(mp)); }
  const mpz_class & get_den() const
  { return reinterpret_cast<const mpz_class &>(*mpq_denref(mp)); }
  mpz_class & get_den()
  { return reinterpret_cast<mpz_class &>(*mpq_denref(mp)); }

  mpq_srcptr get_mpq_t() const { return mp; }
  mpq_ptr get_mpq_t() { return mp; }

  mpz_srcptr get_num_mpz_t() const { return mpq_numref(mp); }
  mpz_ptr get_num_mpz_t() { return mpq_numref(mp); }
  mpz_srcptr get_den_mpz_t() const { return mpq_denref(mp); }
  mpz_ptr get_den_mpz_t() { return mpq_denref(mp); }

  double get_d() const { return mpq_get_d(mp); } // should be long double

  // compound assignments
  __GMPQ_DECLARE_COMPOUND_OPERATOR(operator+=)
  __GMPQ_DECLARE_COMPOUND_OPERATOR(operator-=)
  __GMPQ_DECLARE_COMPOUND_OPERATOR(operator*=)
  __GMPQ_DECLARE_COMPOUND_OPERATOR(operator/=)

  __GMPQ_DECLARE_COMPOUND_OPERATOR_UI(operator<<=)
  __GMPQ_DECLARE_COMPOUND_OPERATOR_UI(operator>>=)

  __GMPQ_DECLARE_INCREMENT_OPERATOR(operator++)
  __GMPQ_DECLARE_INCREMENT_OPERATOR(operator--)
};

typedef __gmp_expr<__gmpq_value, __gmpq_value> mpq_class;


inline std::ostream & operator<<(std::ostream &o, const mpq_class &q)
{
  return o << q.get_mpq_t();
}

template <class T>
inline std::ostream & operator<<
(std::ostream &o, const __gmp_expr<__gmpq_value, T> &expr)
{
  mpq_class temp(expr);
  return o << temp.get_mpq_t();
}

inline std::istream & operator>>(std::istream &i, mpq_class &q)
{
  i >> q.get_mpq_t();
  // q.canonicalize();
  return i;
}


/**************** mpf_class -- wrapper for mpf_t ****************/

template <>
class __gmp_expr<__gmpf_value, __gmpf_value>
{
private:
  mpf_t mp;
public:
  // size information
  unsigned long int get_prec() const { return mpf_get_prec(mp); }

  void set_prec(unsigned long int prec) { mpf_set_prec(mp, prec); }
  void set_prec_raw(unsigned long int prec) { mpf_set_prec_raw(mp, prec); }

  // constructors and destructor
  __gmp_expr() { mpf_init(mp); }

  __gmp_expr(const __gmp_expr &f)
  { mpf_init2(mp, f.get_prec()); mpf_set(mp, f.mp); }
  __gmp_expr(const __gmp_expr &f, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set(mp, f.mp); }
  template <class T, class U>
  __gmp_expr(const __gmp_expr<T, U> &expr)
  { mpf_init2(mp, expr.get_prec()); __gmp_set_expr(mp, expr); }
  template <class T, class U>
  __gmp_expr(const __gmp_expr<T, U> &expr, unsigned long int prec)
  { mpf_init2(mp, prec); __gmp_set_expr(mp, expr); }

  __gmp_expr(signed char c) { mpf_init_set_si(mp, c); }
  __gmp_expr(signed char c, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_si(mp, c); }
  __gmp_expr(unsigned char c) { mpf_init_set_ui(mp, c); }
  __gmp_expr(unsigned char c, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_ui(mp, c); }

  __gmp_expr(signed int i) { mpf_init_set_si(mp, i); }
  __gmp_expr(signed int i, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_si(mp, i); }
  __gmp_expr(unsigned int i) { mpf_init_set_ui(mp, i); }
  __gmp_expr(unsigned int i, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_ui(mp, i); }

  __gmp_expr(signed short int s) { mpf_init_set_si(mp, s); }
  __gmp_expr(signed short int s, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_si(mp, s); }
  __gmp_expr(unsigned short int s) { mpf_init_set_ui(mp, s); }
  __gmp_expr(unsigned short int s, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_ui(mp, s); }

  __gmp_expr(signed long int l) { mpf_init_set_si(mp, l); }
  __gmp_expr(signed long int l, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_si(mp, l); }
  __gmp_expr(unsigned long int l) { mpf_init_set_ui(mp, l); }
  __gmp_expr(unsigned long int l, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_ui(mp, l); }

  __gmp_expr(float f) { mpf_init_set_d(mp, f); }
  __gmp_expr(float f, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_d(mp, f); }
  __gmp_expr(double d) { mpf_init_set_d(mp, d); }
  __gmp_expr(double d, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_d(mp, d); }
  /*
  __gmp_expr(long double ld) { mpf_init_set_d(mp, ld); }
  __gmp_expr(long double ld, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_d(mp, ld); }
  */

  explicit __gmp_expr(const char *s) { mpf_init_set_str(mp, s, 0); }
  __gmp_expr(const char *s, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_str(mp, s, 0); }
  explicit __gmp_expr(const std::string &s)
  { mpf_init_set_str(mp, s.c_str(), 0); }
  __gmp_expr(const std::string &s, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set_str(mp, s.c_str(), 0); }

  explicit __gmp_expr(mpf_srcptr f)
  { mpf_init2(mp, mpf_get_prec(f)); mpf_set(mp, f); }
  __gmp_expr(mpf_srcptr f, unsigned long int prec)
  { mpf_init2(mp, prec); mpf_set(mp, f); }

  ~__gmp_expr() { mpf_clear(mp); }

  // assignment operators
  __gmp_expr & operator=(const __gmp_expr &f)
  { mpf_set(mp, f.mp); return *this; }
  template <class T, class U>
  __gmp_expr<__gmpf_value, __gmpf_value> & operator=
  (const __gmp_expr<T, U> &expr)
  { __gmp_set_expr(mp, expr); return *this; }

  __gmp_expr & operator=(signed char c) { mpf_set_si(mp, c); return *this; }
  __gmp_expr & operator=(unsigned char c) { mpf_set_ui(mp, c); return *this; }

  __gmp_expr & operator=(signed int i) { mpf_set_si(mp, i); return *this; }
  __gmp_expr & operator=(unsigned int i) { mpf_set_ui(mp, i); return *this; }

  __gmp_expr & operator=(signed short int s)
  { mpf_set_si(mp, s); return *this; }
  __gmp_expr & operator=(unsigned short int s)
  { mpf_set_ui(mp, s); return *this; }

  __gmp_expr & operator=(signed long int l)
  { mpf_set_si(mp, l); return *this; }
  __gmp_expr & operator=(unsigned long int l)
  { mpf_set_ui(mp, l); return *this; }

  __gmp_expr & operator=(float f) { mpf_set_d(mp, f); return *this; }
  __gmp_expr & operator=(double d) { mpf_set_d(mp, d); return *this; }
  /*
  __gmp_expr & operator=(long double ld) { mpf_set_ld(mp, ld); return *this; }
  */

  __gmp_expr & operator=(const char *s)
  { mpf_set_str(mp, s, 0); return *this; }
  __gmp_expr & operator=(const std::string &s)
  { mpf_set_str(mp, s.c_str(), 0); return *this; }

  // string input/output functions
  int set_str(const std::string &s, int base)
  { return mpf_set_str(mp, s.c_str(), base); }
  std::string get_str(mp_exp_t *expo, int base, size_t size) const
  {
    __gmp_alloc_cstring temp(mpf_get_str(0, expo, base, size, mp));
    return std::string(temp.str);
  }

  // conversion functions
  mpf_srcptr get_mpf_t() const { return mp; }
  mpf_ptr get_mpf_t() { return mp; }

  signed long int get_si() const { return mpf_get_si(mp); }
  unsigned long int get_ui() const { return mpf_get_ui(mp); }
  double get_d() const { return mpf_get_d(mp); } // should be long double

  // bool fits_schar_p() const { return mpf_fits_schar_p(mp); }
  // bool fits_uchar_p() const { return mpf_fits_uchar_p(mp); }
  bool fits_sint_p() const { return mpf_fits_sint_p(mp); }
  bool fits_uint_p() const { return mpf_fits_uint_p(mp); }
  bool fits_sshort_p() const { return mpf_fits_sshort_p(mp); }
  bool fits_ushort_p() const { return mpf_fits_ushort_p(mp); }
  bool fits_slong_p() const { return mpf_fits_slong_p(mp); }
  bool fits_ulong_p() const { return mpf_fits_ulong_p(mp); }
  // bool fits_float_p() const { return mpf_fits_float_p(mp); }
  // bool fits_double_p() const { return mpf_fits_double_p(mp); }
  // bool fits_ldouble_p() const { return mpf_fits_ldouble_p(mp); }

  // compound assignments
  __GMPF_DECLARE_COMPOUND_OPERATOR(operator+=)
  __GMPF_DECLARE_COMPOUND_OPERATOR(operator-=)
  __GMPF_DECLARE_COMPOUND_OPERATOR(operator*=)
  __GMPF_DECLARE_COMPOUND_OPERATOR(operator/=)

  __GMPF_DECLARE_COMPOUND_OPERATOR_UI(operator<<=)
  __GMPF_DECLARE_COMPOUND_OPERATOR_UI(operator>>=)

  __GMPF_DECLARE_INCREMENT_OPERATOR(operator++)
  __GMPF_DECLARE_INCREMENT_OPERATOR(operator--)
};

typedef __gmp_expr<__gmpf_value, __gmpf_value> mpf_class;


inline std::ostream & operator<<(std::ostream &o, const mpf_class &f)
{
  return o << f.get_mpf_t();
}

template <class T>
inline std::ostream & operator<<
(std::ostream &o, const __gmp_expr<__gmpf_value, T> &expr)
{
  mpf_class temp(expr);
  return o << temp.get_mpf_t();
}

inline std::istream & operator>>(std::istream &i, mpf_class &f)
{
  return i >> f.get_mpf_t();
}


/**************** Classes for type conversion ****************/
/* If the expression to be converted is a plain mp[zqf]_class, a direct
   reference to its mp[zqf]_t internal yields optimal efficiency.
   If it's a compound expression, a temporary must be used */

class __gmpz_temp
{
private:
  mpz_srcptr mp;
  bool is_temp;
  mpz_t temp;

  __gmpz_temp();
  __gmpz_temp(const __gmpz_temp &);
  void operator=(const __gmpz_temp &);
public:
  __gmpz_temp(const mpz_class &z) : mp(z.get_mpz_t()), is_temp(false) { }
  __gmpz_temp(const mpz_classref &z) : mp(z.get_mpz_t()), is_temp(false) { }
  template <class T, class U>
  __gmpz_temp(const __gmp_expr<T, U> &expr)
  {
    mpz_init(temp);
    __gmp_set_expr(temp, expr);
    mp = temp;
    is_temp = true;
  }
  ~__gmpz_temp() { if (is_temp) mpz_clear(temp); }

  mpz_srcptr get_mp() const { return mp; }
};

class __gmpq_temp
{
private:
  mpq_srcptr mp;
  bool is_temp;
  mpq_t temp;

  __gmpq_temp();
  __gmpq_temp(const __gmpq_temp &);
  void operator=(const __gmpq_temp &);
public:
  __gmpq_temp(const mpq_class &q) : mp(q.get_mpq_t()), is_temp(false) { }
  template <class T, class U>
  __gmpq_temp(const __gmp_expr<T, U> &expr)
  {
    mpq_init(temp);
    __gmp_set_expr(temp, expr);
    mp = temp;
    is_temp = true;
  }
  ~__gmpq_temp() { if (is_temp) mpq_clear(temp); }

  mpq_srcptr get_mp() const { return mp; }
};

class __gmpf_temp
{
private:
  mpf_srcptr mp;
  bool is_temp;
  mpf_t temp;

  __gmpf_temp();
  __gmpf_temp(const __gmpf_temp &);
  void operator=(const __gmpf_temp &);
public:
  __gmpf_temp(const mpf_class &f) : mp(f.get_mpf_t()), is_temp(false) { }
  __gmpf_temp(const mpf_class &f, unsigned long int)
    : mp(f.get_mpf_t()), is_temp(false) { }
  template <class T, class U>
  __gmpf_temp(const __gmp_expr<T, U> &expr)
  {
    mpf_init2(temp, expr.get_prec());
    __gmp_set_expr(temp, expr);
    mp = temp;
    is_temp = true;
  }
  template <class T, class U>
  __gmpf_temp(const __gmp_expr<T, U> &expr, unsigned long int prec)
  {
    mpf_init2(temp, prec);
    __gmp_set_expr(temp, expr);
    mp = temp;
    is_temp = true;
  }
  ~__gmpf_temp() { if (is_temp) mpf_clear(temp); }

  mpf_srcptr get_mp() const { return mp; }
};


// this function must be defined after __gmpz_temp
template <class T, class U>
inline mpq_class::__gmp_expr(const __gmp_expr<__gmpz_value, T> &num,
                             const __gmp_expr<__gmpz_value, U> &den)
{
  __gmpz_temp temp1(num), temp2(den);
  mpq_init(mp);
  mpz_set(mpq_numref(mp), temp1.get_mp());
  mpz_set(mpq_denref(mp), temp2.get_mp());
}


// type of mixed-type expressions
template <class T, class U>
struct __gmp_resolve_expr;

template <>
struct __gmp_resolve_expr<__gmpz_value, __gmpz_value>
{
  typedef __gmpz_value value_type;
  typedef __gmpz_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpq_value, __gmpq_value>
{
  typedef __gmpq_value value_type;
  typedef __gmpq_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpz_value, __gmpq_value>
{
  typedef __gmpq_value value_type;
  typedef __gmpq_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpq_value, __gmpz_value>
{
  typedef __gmpq_value value_type;
  typedef __gmpq_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpf_value, __gmpf_value>
{
  typedef __gmpf_value value_type;
  typedef __gmpf_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpz_value, __gmpf_value>
{
  typedef __gmpf_value value_type;
  typedef __gmpf_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpf_value, __gmpz_value>
{
  typedef __gmpf_value value_type;
  typedef __gmpf_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpq_value, __gmpf_value>
{
  typedef __gmpf_value value_type;
  typedef __gmpf_temp temp_type;
};

template <>
struct __gmp_resolve_expr<__gmpf_value, __gmpq_value>
{
  typedef __gmpf_value value_type;
  typedef __gmpf_temp temp_type;
};


// perform type conversions

template <>
inline void __gmp_set_expr(mpz_ptr z, const mpz_class &w)
{
  mpz_set(z, w.get_mpz_t());
}

template <class T>
inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr<__gmpz_value, T> &expr)
{
  expr.eval(z);
}

template <>
inline void __gmp_set_expr(mpz_ptr z, const mpz_classref &w)
{
  mpz_set(z, w.get_mpz_t());
}

template <>
inline void __gmp_set_expr(mpz_ptr z, const mpq_class &q)
{
  mpz_set_q(z, q.get_mpq_t());
}

template <class T>
inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr<__gmpq_value, T> &expr)
{
  mpq_class temp(expr);
  mpz_set_q(z, temp.get_mpq_t());
}

template <class T>
inline void __gmp_set_expr(mpz_ptr z, const mpf_class &f)
{
  mpz_set_f(z, f.get_mpf_t());
}

template <class T>
inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr<__gmpf_value, T> &expr)
{
  mpf_class temp(expr);
  mpz_set_f(z, temp.get_mpf_t());
}

template <>
inline void __gmp_set_expr(mpq_ptr q, const mpz_class &z)
{
  mpq_set_z(q, z.get_mpz_t());
}

template <class T>
inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr<__gmpz_value, T> &expr)
{
  mpz_class temp(expr);
  mpq_set_z(q, temp.get_mpz_t());
}

template <>
inline void __gmp_set_expr(mpq_ptr q, const mpz_classref &z)
{
  mpq_set_z(q, z.get_mpz_t());
}

template <>
inline void __gmp_set_expr(mpq_ptr q, const mpq_class &r)
{
  mpq_set(q, r.get_mpq_t());
}

template <class T>
inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr<__gmpq_value, T> &expr)
{
  expr.eval(q);
}

template <class T>
inline void __gmp_set_expr(mpq_ptr q, const mpf_class &f)
{
  mpq_set_f(q, f.get_mpf_t());
}

template <class T>
inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr<__gmpf_value, T> &expr)
{
  mpf_class temp(expr);
  mpq_set_f(q, temp.get_mpf_t());
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const mpz_class &z)
{
  mpf_set_z(f, z.get_mpz_t());
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr<__gmpz_value, T> &expr)
{
  mpz_class temp(expr);
  mpf_set_z(f, temp.get_mpz_t());
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const mpz_classref &z)
{
  mpf_set_z(f, z.get_mpz_t());
}

template <>
inline void __gmp_set_expr(mpf_ptr f, const mpf_class &g)
{
  mpf_set(f, g.get_mpf_t());
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr<__gmpf_value, T> &expr)
{
  expr.eval(f, mpf_get_prec(f));
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const mpq_class &q)
{
  mpf_set_q(f, q.get_mpq_t());
}

template <class T>
inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr<__gmpq_value, T> &expr)
{
  mpq_class temp(expr);
  mpf_set_q(f, temp.get_mpq_t());
}




/**************** Specializations of __gmp_expr ****************/
/* The eval() method of __gmp_expr<T, U> evaluates the corresponding
   expression assigning the result to its argument, which is either an
   mpz_t, mpq_t, or mpf_t -- this depends on the T argument, which is
   either __gmpz_value, __gmpq_value, or __gmpf_value, respectively.
   Compound expressions are evaluated recursively (temporaries are created
   to hold intermediate values), while for simple expressions the eval()
   method of the appropriate function object (available as the Op argument
   of either __gmp_unary_expr<T, Op> or __gmp_binary_expr<T, U, Op>) is
   called. */

/**************** Unary expressions ****************/
/* cases:
   - simple:   argument is mp[zqf]_class, or mpz_classref
   - compound: argument is __gmp_expr<...> */


// simple expressions

template <class Op>
class __gmp_expr<__gmpz_value, __gmp_unary_expr<mpz_class, Op> >
{
private:
  __gmp_unary_expr<mpz_class, Op> expr;
public:
  __gmp_expr(const mpz_class &val) : expr(val) { }
  void eval(mpz_ptr z) const { Op::eval(z, expr.val.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr<__gmpz_value, __gmp_unary_expr<mpz_classref, Op> >
{
private:
  __gmp_unary_expr<mpz_classref, Op> expr;
public:
  __gmp_expr(const mpz_classref &val) : expr(val) { }
  void eval(mpz_ptr z) const { Op::eval(z, expr.val.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr<__gmpq_value, __gmp_unary_expr<mpq_class, Op> >
{
private:
  __gmp_unary_expr<mpq_class, Op> expr;
public:
  __gmp_expr(const mpq_class &val) : expr(val) { }
  void eval(mpq_ptr q) const { Op::eval(q, expr.val.get_mpq_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr<__gmpf_value, __gmp_unary_expr<mpf_class, Op> >
{
private:
  __gmp_unary_expr<mpf_class, Op> expr;
public:
  __gmp_expr(const mpf_class &val) : expr(val) { }
  void eval(mpf_ptr f, unsigned long int) const
  { Op::eval(f, expr.val.get_mpf_t()); }
  unsigned long int get_prec() const
  { return mpf_get_prec(expr.val.get_mpf_t()); }
};


// compound expressions

template <class T, class U, class Op>
class __gmp_expr<__gmpz_value, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
{
private:
  __gmp_unary_expr<__gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val) : expr(val) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val);
    Op::eval(z, temp.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr<__gmpq_value, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
{
private:
  __gmp_unary_expr<__gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val) : expr(val) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp(expr.val);
    Op::eval(q, temp.get_mpq_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr<__gmpf_value, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
{
private:
  __gmp_unary_expr<__gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val) : expr(val) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp(expr.val, prec);
    Op::eval(f, temp.get_mpf_t());
  }
  unsigned long int get_prec() const { return expr.val.get_prec(); }
};


/**************** Binary expressions ****************/
/* simple:
   - arguments are both mp[zqf]_class, or mpz_classref
   - one argument is mp[zqf]_class(ref), one is a built-in type
   compound:
   - one is mp[zqf]_class(ref), one is __gmp_expr<...>
   - one is __gmp_expr<...>, one is built-in
   - both arguments are __gmp_expr<...> */


// simple expressions

template <class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<mpz_class, mpz_class, Op> >
{
private:
  __gmp_binary_expr<mpz_class, mpz_class, Op> expr;
public:
  __gmp_expr(const mpz_class &val1, const mpz_class &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<mpz_class, mpz_classref, Op> >
{
private:
  __gmp_binary_expr<mpz_class, mpz_classref, Op> expr;
public:
  __gmp_expr(const mpz_class &val1, const mpz_classref &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<mpz_classref, mpz_class, Op> >
{
private:
  __gmp_binary_expr<mpz_classref, mpz_class, Op> expr;
public:
  __gmp_expr(const mpz_classref &val1, const mpz_class &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<mpz_classref, mpz_classref, Op> >
{
private:
  __gmp_binary_expr<mpz_classref, mpz_classref, Op> expr;
public:
  __gmp_expr(const mpz_classref &val1, const mpz_classref &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr<__gmpq_value, __gmp_binary_expr<mpq_class, mpq_class, Op> >
{
private:
  __gmp_binary_expr<mpq_class, mpq_class, Op> expr;
public:
  __gmp_expr(const mpq_class &val1, const mpq_class &val2)
    : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  { Op::eval(q, expr.val1.get_mpq_t(), expr.val2.get_mpq_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class Op>
class __gmp_expr<__gmpf_value, __gmp_binary_expr<mpf_class, mpf_class, Op> >
{
private:
  __gmp_binary_expr<mpf_class, mpf_class, Op> expr;
public:
  __gmp_expr(const mpf_class &val1, const mpf_class &val2)
    : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int) const
  { Op::eval(f, expr.val1.get_mpf_t(), expr.val2.get_mpf_t()); }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};


// simple expressions, T is a built-in numerical type

template <class T, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<mpz_class, T, Op> >
{
private:
  __gmp_binary_expr<mpz_class, T, Op> expr;
public:
  __gmp_expr(const mpz_class &val1, T val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<T, mpz_class, Op> >
{
private:
  __gmp_binary_expr<T, mpz_class, Op> expr;
public:
  __gmp_expr(T val1, const mpz_class &val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1, expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<mpz_classref, T, Op> >
{
private:
  __gmp_binary_expr<mpz_classref, T, Op> expr;
public:
  __gmp_expr(const mpz_classref &val1, T val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1.get_mpz_t(), expr.val2); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<T, mpz_classref, Op> >
{
private:
  __gmp_binary_expr<T, mpz_classref, Op> expr;
public:
  __gmp_expr(T val1, const mpz_classref &val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  { Op::eval(z, expr.val1, expr.val2.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpq_value, __gmp_binary_expr<mpq_class, T, Op> >
{
private:
  __gmp_binary_expr<mpq_class, T, Op> expr;
public:
  __gmp_expr(const mpq_class &val1, T val2) : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  { Op::eval(q, expr.val1.get_mpq_t(), expr.val2); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpq_value, __gmp_binary_expr<T, mpq_class, Op> >
{
private:
  __gmp_binary_expr<T, mpq_class, Op> expr;
public:
  __gmp_expr(T val1, const mpq_class &val2) : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  { Op::eval(q, expr.val1, expr.val2.get_mpq_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class Op>
class __gmp_expr<__gmpf_value, __gmp_binary_expr<mpf_class, T, Op> >
{
private:
  __gmp_binary_expr<mpf_class, T, Op> expr;
public:
  __gmp_expr(const mpf_class &val1, T val2) : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int) const
  { Op::eval(f, expr.val1.get_mpf_t(), expr.val2); }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = mpf_get_default_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};

template <class T, class Op>
class __gmp_expr<__gmpf_value, __gmp_binary_expr<T, mpf_class, Op> >
{
private:
  __gmp_binary_expr<T, mpf_class, Op> expr;
public:
  __gmp_expr(T val1, const mpf_class &val2) : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int) const
  { Op::eval(f, expr.val1, expr.val2.get_mpf_t()); }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = mpf_get_default_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};


// compound expressions, one argument is a subexpression

template <class T, class U, class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<mpz_class, __gmp_expr<T, U>, Op> >
{
private:
  __gmp_binary_expr<mpz_class, __gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const mpz_class &val1, const __gmp_expr<T, U> &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val2);
    Op::eval(z, expr.val1.get_mpz_t(), temp.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<__gmp_expr<T, U>, mpz_class, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, mpz_class, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const mpz_class &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val1);
    Op::eval(z, temp.get_mpz_t(), expr.val2.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<mpz_classref, __gmp_expr<T, U>, Op> >
{
private:
  __gmp_binary_expr<mpz_classref, __gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const mpz_classref &val1, const __gmp_expr<T, U> &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val2);
    Op::eval(z, expr.val1.get_mpz_t(), temp.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<__gmp_expr<T, U>, mpz_classref, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, mpz_classref, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const mpz_classref &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val1);
    Op::eval(z, temp.get_mpz_t(), expr.val2.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpq_value, __gmp_binary_expr<mpq_class, __gmp_expr<T, U>, Op> >
{
private:
  __gmp_binary_expr<mpq_class, __gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const mpq_class &val1, const __gmp_expr<T, U> &val2)
    : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp(expr.val2);
    Op::eval(q, expr.val1.get_mpq_t(), temp.get_mpq_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpq_value, __gmp_binary_expr<__gmp_expr<T, U>, mpq_class, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, mpq_class, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const mpq_class &val2)
    : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp(expr.val1);
    Op::eval(q, temp.get_mpq_t(), expr.val2.get_mpq_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpf_value, __gmp_binary_expr<mpf_class, __gmp_expr<T, U>, Op> >
{
private:
  __gmp_binary_expr<mpf_class, __gmp_expr<T, U>, Op> expr;
public:
  __gmp_expr(const mpf_class &val1, const __gmp_expr<T, U> &val2)
    : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp(expr.val2, prec);
    Op::eval(f, expr.val1.get_mpf_t(), temp.get_mpf_t());
  }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};

template <class T, class U, class Op>
class __gmp_expr
<__gmpf_value, __gmp_binary_expr<__gmp_expr<T, U>, mpf_class, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, mpf_class, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const mpf_class &val2)
    : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp(expr.val1, prec);
    Op::eval(f, temp.get_mpf_t(), expr.val2.get_mpf_t());
  }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};


// one argument is a subexpression, one is a built-in

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<__gmp_expr<T, U>, V, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, V, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, V val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val1);
    Op::eval(z, temp.get_mpz_t(), expr.val2);
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpz_value, __gmp_binary_expr<T, __gmp_expr<U, V>, Op> >
{
private:
  __gmp_binary_expr<T, __gmp_expr<U, V>, Op> expr;
public:
  __gmp_expr(T val1, const __gmp_expr<U, V> &val2) : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp(expr.val2);
    Op::eval(z, expr.val1, temp.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpq_value, __gmp_binary_expr<__gmp_expr<T, U>, V, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, V, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, V val2) : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp(expr.val1);
    Op::eval(q, temp.get_mpq_t(), expr.val2);
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpq_value, __gmp_binary_expr<T, __gmp_expr<U, V>, Op> >
{
private:
  __gmp_binary_expr<T, __gmp_expr<U, V>, Op> expr;
public:
  __gmp_expr(T val1, const __gmp_expr<U, V> &val2) : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp(expr.val2);
    Op::eval(q, expr.val1, temp.get_mpq_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpf_value, __gmp_binary_expr<__gmp_expr<T, U>, V, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, V, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, V val2) : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp(expr.val1, prec);
    Op::eval(f, temp.get_mpf_t(), expr.val2);
  }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = mpf_get_default_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};

template <class T, class U, class V, class Op>
class __gmp_expr<__gmpf_value, __gmp_binary_expr<T, __gmp_expr<U, V>, Op> >
{
private:
  __gmp_binary_expr<T, __gmp_expr<U, V>, Op> expr;
public:
  __gmp_expr(T val1, const __gmp_expr<U, V> &val2) : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp(expr.val2, prec);
    Op::eval(f, expr.val1, temp.get_mpf_t());
  }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = mpf_get_default_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};


// both arguments are subexpressions

template <class T, class U, class V, class W, class Op>
class __gmp_expr
<__gmpz_value, __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, Op> >
{
private:
  __gmp_binary_expr
  <__gmp_expr<T, U>, __gmp_expr<V, W>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const __gmp_expr<V, W> &val2)
    : expr(val1, val2) { }
  void eval(mpz_ptr z) const
  {
    mpz_class temp1(expr.val1), temp2(expr.val2);
    Op::eval(z, temp1.get_mpz_t(), temp2.get_mpz_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class W, class Op>
class __gmp_expr
<__gmpq_value, __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const __gmp_expr<V, W> &val2)
    : expr(val1, val2) { }
  void eval(mpq_ptr q) const
  {
    mpq_class temp1(expr.val1), temp2(expr.val2);
    Op::eval(q, temp1.get_mpq_t(), temp2.get_mpq_t());
  }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <class T, class U, class V, class W, class Op>
class __gmp_expr
<__gmpf_value, __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, Op> >
{
private:
  __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, Op> expr;
public:
  __gmp_expr(const __gmp_expr<T, U> &val1, const __gmp_expr<V, W> &val2)
    : expr(val1, val2) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  {
    mpf_class temp1(expr.val1, prec), temp2(expr.val2, prec);
    Op::eval(f, temp1.get_mpf_t(), temp2.get_mpf_t());
  }
  unsigned long int get_prec() const
  {
    unsigned long int prec1 = expr.val1.get_prec(),
      prec2 = expr.val2.get_prec();
    return (prec1 > prec2) ? prec1 : prec2;
  }
};


/**************** Special cases ****************/
/* Some operations (i.e., add and subtract) with mixed mpz/mpq arguments
   can be done directly without first converting the mpz to mpq.
   Appropriate specializations are required. */


#define __GMPZQ_DEFINE_EXPR(eval_fun)                                        \
                                                                             \
template <>                                                                  \
class __gmp_expr                                                             \
<__gmpq_value, __gmp_binary_expr<mpz_class, mpq_class, eval_fun> >           \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<mpz_class, mpq_class, eval_fun> expr;                    \
public:                                                                      \
  __gmp_expr(const mpz_class &val1, const mpq_class &val2)                   \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  { eval_fun::eval(q, expr.val1.get_mpz_t(), expr.val2.get_mpq_t()); }       \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <>                                                                  \
class __gmp_expr                                                             \
<__gmpq_value, __gmp_binary_expr<mpq_class, mpz_class, eval_fun> >           \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<mpq_class, mpz_class, eval_fun> expr;                    \
public:                                                                      \
  __gmp_expr(const mpq_class &val1, const mpz_class &val2)                   \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  { eval_fun::eval(q, expr.val1.get_mpq_t(), expr.val2.get_mpz_t()); }       \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T>                                                           \
class __gmp_expr<__gmpq_value,                                               \
  __gmp_binary_expr<mpz_class, __gmp_expr<__gmpq_value, T>, eval_fun> >      \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<mpz_class, __gmp_expr<__gmpq_value, T>, eval_fun> expr;  \
public:                                                                      \
  __gmp_expr(const mpz_class &val1, const __gmp_expr<__gmpq_value, T> &val2) \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpq_class temp(expr.val2);                                               \
    eval_fun::eval(q, expr.val1.get_mpz_t(), temp.get_mpq_t());              \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T>                                                           \
class __gmp_expr<__gmpq_value,                                               \
  __gmp_binary_expr<mpq_class, __gmp_expr<__gmpz_value, T>, eval_fun> >      \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<mpq_class, __gmp_expr<__gmpz_value, T>, eval_fun> expr;  \
public:                                                                      \
  __gmp_expr(const mpq_class &val1, const __gmp_expr<__gmpz_value, T> &val2) \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpz_class temp(expr.val2);                                               \
    eval_fun::eval(q, expr.val1.get_mpq_t(), temp.get_mpz_t());              \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T>                                                           \
class __gmp_expr<__gmpq_value,                                               \
  __gmp_binary_expr<__gmp_expr<__gmpz_value, T>, mpq_class, eval_fun> >      \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<__gmp_expr<__gmpz_value, T>, mpq_class, eval_fun> expr;  \
public:                                                                      \
  __gmp_expr(const __gmp_expr<__gmpz_value, T> &val1, const mpq_class &val2) \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpz_class temp(expr.val1);                                               \
    eval_fun::eval(q, temp.get_mpz_t(), expr.val2.get_mpq_t());              \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T>                                                           \
class __gmp_expr<__gmpq_value,                                               \
  __gmp_binary_expr<__gmp_expr<__gmpq_value, T>, mpz_class, eval_fun> >      \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr<__gmp_expr<__gmpq_value, T>, mpz_class, eval_fun> expr;  \
public:                                                                      \
  __gmp_expr(const __gmp_expr<__gmpq_value, T> &val1, const mpz_class &val2) \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpq_class temp(expr.val1);                                               \
    eval_fun::eval(q, temp.get_mpq_t(), expr.val2.get_mpz_t());              \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T, class U>                                                  \
class __gmp_expr<__gmpq_value, __gmp_binary_expr                             \
<__gmp_expr<__gmpz_value, T>, __gmp_expr<__gmpq_value, U>, eval_fun> >       \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr                                                          \
  <__gmp_expr<__gmpz_value, T>, __gmp_expr<__gmpq_value, U>, eval_fun> expr; \
public:                                                                      \
  __gmp_expr(const __gmp_expr<__gmpz_value, T> &val1,                        \
             const __gmp_expr<__gmpq_value, U> &val2)                        \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpz_class temp1(expr.val1);                                              \
    mpq_class temp2(expr.val2);                                              \
    eval_fun::eval(q, temp1.get_mpz_t(), temp2.get_mpq_t());                 \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};                                                                           \
                                                                             \
template <class T, class U>                                                  \
class __gmp_expr<__gmpq_value, __gmp_binary_expr                             \
<__gmp_expr<__gmpq_value, T>, __gmp_expr<__gmpz_value, U>, eval_fun> >       \
{                                                                            \
private:                                                                     \
  __gmp_binary_expr                                                          \
  <__gmp_expr<__gmpq_value, T>, __gmp_expr<__gmpz_value, U>, eval_fun> expr; \
public:                                                                      \
  __gmp_expr(const __gmp_expr<__gmpq_value, T> &val1,                        \
             const __gmp_expr<__gmpz_value, U> &val2)                        \
    : expr(val1, val2) { }                                                   \
  void eval(mpq_ptr q) const                                                 \
  {                                                                          \
    mpq_class temp1(expr.val1);                                              \
    mpz_class temp2(expr.val2);                                              \
    eval_fun::eval(q, temp1.get_mpq_t(), temp2.get_mpz_t());                 \
  }                                                                          \
  unsigned long int get_prec() const { return mpf_get_default_prec(); }      \
};


__GMPZQ_DEFINE_EXPR(__gmp_binary_plus)
__GMPZQ_DEFINE_EXPR(__gmp_binary_minus)


/**************** Macros for defining functions ****************/
/* Results of operators and functions are __gmp_expr<T, U> objects.
   T determines the numerical type of the expression: it can be either
   __gmpz_value, __gmpq_value, or __gmpf_value.
   U is either __gmp_unary_expr<V, Op> or __gmp_binary_expr<V, W, Op>,
   where V and W are the arguments' types -- they can in turn be
   expressions, thus allowing to build compound expressions to any
   degree of complexity.  Op is a function object that must have an
   eval() method accepting appropriate arguments.
   When the arguments of a binary expression have different numerical
   types, __gmp_resolve_expr is used to determine the "larger" type.
   Actual evaluation of a __gmp_expr<T, U> object is done when it gets
   assigned to an mp[zqf]_class: this is done by calling its eval()
   method. */

// non-member operators and functions

#define __GMP_DEFINE_UNARY_FUNCTION(fun, eval_fun)                           \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, eval_fun> >          \
fun(const __gmp_expr<T, U> &expr)                                            \
{                                                                            \
  return __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, eval_fun> >(expr); \
}

#define __GMP_DEFINE_BINARY_FUNCTION(fun, eval_fun)                          \
                                                                             \
template <class T, class U, class V, class W>                                \
inline __gmp_expr<typename __gmp_resolve_expr<T, V>::value_type,             \
__gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, eval_fun> >            \
fun(const __gmp_expr<T, U> &expr1, const __gmp_expr<V, W> &expr2)            \
{                                                                            \
  return __gmp_expr<typename __gmp_resolve_expr<T, V>::value_type,           \
     __gmp_binary_expr<__gmp_expr<T, U>, __gmp_expr<V, W>, eval_fun> >       \
    (expr1, expr2);                                                          \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, signed long int, eval_fun> >         \
fun(const __gmp_expr<T, U> &expr, signed char c)                             \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, signed long int, eval_fun> >(expr, c);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<signed long int, __gmp_expr<T, U>, eval_fun> >         \
fun(signed char c, const __gmp_expr<T, U> &expr)                             \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <signed long int, __gmp_expr<T, U>, eval_fun> >(c, expr);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, unsigned long int, eval_fun> >       \
fun(const __gmp_expr<T, U> &expr, unsigned char c)                           \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, unsigned long int, eval_fun> >(expr, c);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<unsigned long int, __gmp_expr<T, U>, eval_fun> >       \
fun(unsigned char c, const __gmp_expr<T, U> &expr)                           \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <unsigned long int, __gmp_expr<T, U>, eval_fun> >(c, expr);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, signed long int, eval_fun> >         \
fun(const __gmp_expr<T, U> &expr, signed int i)                              \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, signed long int, eval_fun> >(expr, i);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<signed long int, __gmp_expr<T, U>, eval_fun> >         \
fun(signed int i, const __gmp_expr<T, U> &expr)                              \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <signed long int, __gmp_expr<T, U>, eval_fun> >(i, expr);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, unsigned long int, eval_fun> >       \
fun(const __gmp_expr<T, U> &expr, unsigned int i)                            \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, unsigned long int, eval_fun> >(expr, i);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<unsigned long int, __gmp_expr<T, U>, eval_fun> >       \
fun(unsigned int i, const __gmp_expr<T, U> &expr)                            \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <unsigned long int, __gmp_expr<T, U>, eval_fun> >(i, expr);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, signed long int, eval_fun> >         \
fun(const __gmp_expr<T, U> &expr, signed short int s)                        \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, signed long int, eval_fun> >(expr, s);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<signed long int, __gmp_expr<T, U>, eval_fun> >         \
fun(signed short int s, const __gmp_expr<T, U> &expr)                        \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <signed long int, __gmp_expr<T, U>, eval_fun> >(s, expr);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, unsigned long int, eval_fun> >       \
fun(const __gmp_expr<T, U> &expr, unsigned short int s)                      \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, unsigned long int, eval_fun> >(expr, s);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<unsigned long int, __gmp_expr<T, U>, eval_fun> >       \
fun(unsigned short int s, const __gmp_expr<T, U> &expr)                      \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <unsigned long int, __gmp_expr<T, U>, eval_fun> >(s, expr);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, signed long int, eval_fun> >         \
fun(const __gmp_expr<T, U> &expr, signed long int l)                         \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, signed long int, eval_fun> >(expr, l);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<signed long int, __gmp_expr<T, U>, eval_fun> >         \
fun(signed long int l, const __gmp_expr<T, U> &expr)                         \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <signed long int, __gmp_expr<T, U>, eval_fun> >(l, expr);                \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, unsigned long int, eval_fun> >       \
fun(const __gmp_expr<T, U> &expr, unsigned long int l)                       \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, unsigned long int, eval_fun> >(expr, l);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<unsigned long int, __gmp_expr<T, U>, eval_fun> >       \
fun(unsigned long int l, const __gmp_expr<T, U> &expr)                       \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <unsigned long int, __gmp_expr<T, U>, eval_fun> >(l, expr);              \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr<T, __gmp_binary_expr<__gmp_expr<T, U>, double, eval_fun> > \
fun(const __gmp_expr<T, U> &expr, float f)                                   \
{                                                                            \
  return __gmp_expr                                                          \
    <T, __gmp_binary_expr<__gmp_expr<T, U>, double, eval_fun> >(expr, f);    \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr<T, __gmp_binary_expr<double, __gmp_expr<T, U>, eval_fun> > \
fun(float f, const __gmp_expr<T, U> &expr)                                   \
{                                                                            \
  return __gmp_expr                                                          \
    <T, __gmp_binary_expr<double, __gmp_expr<T, U>, eval_fun> >(f, expr);    \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr<T, __gmp_binary_expr<__gmp_expr<T, U>, double, eval_fun> > \
fun(const __gmp_expr<T, U> &expr, double d)                                  \
{                                                                            \
  return __gmp_expr                                                          \
    <T, __gmp_binary_expr<__gmp_expr<T, U>, double, eval_fun> >(expr, d);    \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr<T, __gmp_binary_expr<double, __gmp_expr<T, U>, eval_fun> > \
fun(double d, const __gmp_expr<T, U> &expr)                                  \
{                                                                            \
  return __gmp_expr                                                          \
    <T, __gmp_binary_expr<double, __gmp_expr<T, U>, eval_fun> >(d, expr);    \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<__gmp_expr<T, U>, long double, eval_fun> >             \
fun(const __gmp_expr<T, U> &expr, long double ld)                            \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <__gmp_expr<T, U>, long double, eval_fun> >(expr, ld);                   \
}                                                                            \
                                                                             \
template <class T, class U>                                                  \
inline __gmp_expr                                                            \
<T, __gmp_binary_expr<long double, __gmp_expr<T, U>, eval_fun> >             \
fun(long double ld, const __gmp_expr<T, U> &expr)                            \
{                                                                            \
  return __gmp_expr<T, __gmp_binary_expr                                     \
    <long double, __gmp_expr<T, U>, eval_fun> >(ld, expr);                   \
}

#define __GMP_DEFINE_BINARY_FUNCTION_UI(fun, eval_fun)                 \
                                                                       \
template <class T, class U>                                            \
inline __gmp_expr                                                      \
<T, __gmp_binary_expr<__gmp_expr<T, U>, unsigned long int, eval_fun> > \
fun(const __gmp_expr<T, U> &expr, unsigned long int l)                 \
{                                                                      \
  return __gmp_expr<T, __gmp_binary_expr                               \
    <__gmp_expr<T, U>, unsigned long int, eval_fun> >(expr, l);        \
}

#define __GMP_DEFINE_UNARY_TYPE_FUNCTION(type, fun, eval_fun) \
                                                              \
template <class T, class U>                                   \
inline type fun(const __gmp_expr<T, U> &expr)                 \
{                                                             \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);    \
  return eval_fun::eval(temp.get_mp());                       \
}

#define __GMP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun)             \
                                                                           \
template <class T, class U, class V, class W>                              \
inline type fun(const __gmp_expr<T, U> &expr1,                             \
                const __gmp_expr<V, W> &expr2)                             \
{                                                                          \
  typename __gmp_resolve_expr<T, V>::temp_type temp1(expr1), temp2(expr2); \
  return eval_fun::eval(temp1.get_mp(), temp2.get_mp());                   \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr1,                             \
                const __gmp_expr<T, U> &expr2)                             \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp1(expr1), temp2(expr2); \
  return eval_fun::eval(temp1.get_mp(), temp2.get_mp());                   \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, signed char c)               \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (signed long int) c);               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(signed char c, const __gmp_expr<T, U> &expr)               \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((signed long int) c, temp.get_mp());               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, unsigned char c)             \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (unsigned long int) c);             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(unsigned char c, const __gmp_expr<T, U> &expr)             \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((unsigned long int) c, temp.get_mp());             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, signed int i)                \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (signed long int) i);               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(signed int i, const __gmp_expr<T, U> &expr)                \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((signed long int) i, temp.get_mp());               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, unsigned int i)              \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (unsigned long int) i);             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(unsigned int i, const __gmp_expr<T, U> &expr)              \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((unsigned long int) i, temp.get_mp());             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, signed short int s)          \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (signed long int) s);               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(signed short int s, const __gmp_expr<T, U> &expr)          \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((signed long int) s, temp.get_mp());               \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, unsigned short int s)        \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (unsigned long int) s);             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(unsigned short int s, const __gmp_expr<T, U> &expr)        \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((unsigned long int) s, temp.get_mp());             \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, signed long int l)           \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), l);                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(signed long int l, const __gmp_expr<T, U> &expr)           \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(l, temp.get_mp());                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, unsigned long int l)         \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), l);                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(unsigned long int l, const __gmp_expr<T, U> &expr)         \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(l, temp.get_mp());                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, float f)                     \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), (double) f);                        \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(float f, const __gmp_expr<T, U> &expr)                     \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval((double) f, temp.get_mp());                        \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, double d)                    \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), d);                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(double d, const __gmp_expr<T, U> &expr)                    \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(d, temp.get_mp());                                 \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(const __gmp_expr<T, U> &expr, long double ld)              \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(temp.get_mp(), ld);                                \
}                                                                          \
                                                                           \
template <class T, class U>                                                \
inline type fun(long double ld, const __gmp_expr<T, U> &expr)              \
{                                                                          \
  typename __gmp_resolve_expr<T, T>::temp_type temp(expr);                 \
  return eval_fun::eval(ld, temp.get_mp());                                \
}


// member operators for mpz_class

#define __GMPZZ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)         \
                                                                \
template <class T, class U>                                     \
inline mpz_class & mpz_class::fun(const __gmp_expr<T, U> &expr) \
{                                                               \
  __gmpz_temp temp(expr);                                       \
  eval_fun::eval(mp, mp, temp.get_mp());                        \
  return *this;                                                 \
}

#define __GMPZN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
                                                        \
inline mpz_class & mpz_class::fun(signed char c)        \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) c);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(unsigned char c)      \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) c);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(signed int i)         \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) i);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(unsigned int i)       \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) i);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(signed short int s)   \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) s);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(unsigned short int s) \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) s);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(signed long int l)    \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(unsigned long int l)  \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(float f)              \
{                                                       \
  eval_fun::eval(mp, mp, (double) f);                   \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class & mpz_class::fun(double d)             \
{                                                       \
  eval_fun::eval(mp, mp, d);                            \
  return *this;                                         \
}                                                       \
                                                        \
/*                                                      \
inline mpz_class & mpz_class::fun(long double ld)       \
{                                                       \
  eval_fun::eval(mp, mp, ld);                           \
  return *this;                                         \
} */

#define __GMPZ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
__GMPZZ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)        \
__GMPZN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)

#define __GMPZ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \
                                                          \
inline mpz_class & mpz_class::fun(unsigned long int l)    \
{                                                         \
  eval_fun::eval(mp, mp, l);                              \
  return *this;                                           \
}

#define __GMPZ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \
                                                        \
inline mpz_class & mpz_class::fun()                     \
{                                                       \
  eval_fun::eval(mp, mp);                               \
  return *this;                                         \
}                                                       \
                                                        \
inline mpz_class mpz_class::fun(int)                    \
{                                                       \
  mpz_class temp(*this);                                \
  eval_fun::eval(mp, mp);                               \
  return temp;                                          \
}


// member operators for mpz_classref

#define __GMPZRR_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)              \
                                                                      \
template <class T, class U>                                           \
inline mpz_classref & mpz_classref::fun(const __gmp_expr<T, U> &expr) \
{                                                                     \
  __gmpz_temp temp(expr);                                             \
  eval_fun::eval(ref, ref, temp.get_mp());                            \
  return *this;                                                       \
}

#define __GMPZRN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)      \
                                                              \
inline mpz_classref & mpz_classref::fun(signed char c)        \
{                                                             \
  eval_fun::eval(ref, ref, (signed long int) c);              \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(unsigned char c)      \
{                                                             \
  eval_fun::eval(ref, ref, (unsigned long int) c);            \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(signed int i)         \
{                                                             \
  eval_fun::eval(ref, ref, (signed long int) i);              \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(unsigned int i)       \
{                                                             \
  eval_fun::eval(ref, ref, (unsigned long int) i);            \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(signed short int s)   \
{                                                             \
  eval_fun::eval(ref, ref, (signed long int) s);              \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(unsigned short int s) \
{                                                             \
  eval_fun::eval(ref, ref, (unsigned long int) s);            \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(signed long int l)    \
{                                                             \
  eval_fun::eval(ref, ref, l);                                \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(unsigned long int l)  \
{                                                             \
  eval_fun::eval(ref, ref, l);                                \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(float f)              \
{                                                             \
  eval_fun::eval(ref, ref, (double) f);                       \
  return *this;                                               \
}                                                             \
                                                              \
inline mpz_classref & mpz_classref::fun(double d)             \
{                                                             \
  eval_fun::eval(ref, ref, d);                                \
  return *this;                                               \
}                                                             \
                                                              \
/*                                                            \
inline mpz_classref & mpz_classref::fun(long double ld)       \
{                                                             \
  eval_fun::eval(ref, ref, ld);                               \
  return *this;                                               \
} */

#define __GMPZR_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
__GMPZRR_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)        \
__GMPZRN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)

#define __GMPZR_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun)   \
                                                             \
inline mpz_classref & mpz_classref::fun(unsigned long int l) \
{                                                            \
  eval_fun::eval(ref, ref, l);                               \
  return *this;                                              \
}

#define __GMPZR_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \
                                                         \
inline mpz_classref & mpz_classref::fun()                \
{                                                        \
  eval_fun::eval(ref, ref);                              \
  return *this;                                          \
}                                                        \
                                                         \
inline mpz_class mpz_classref::fun(int)                  \
{                                                        \
  mpz_class temp(*this);                                 \
  eval_fun::eval(ref, ref);                              \
  return temp;                                           \
}


// member operators for mpq_class

#define __GMPQQ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)         \
                                                                \
template <class T, class U>                                     \
inline mpq_class & mpq_class::fun(const __gmp_expr<T, U> &expr) \
{                                                               \
  __gmpq_temp temp(expr);                                       \
  eval_fun::eval(mp, mp, temp.get_mp());                        \
  return *this;                                                 \
}

#define __GMPQN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
                                                        \
inline mpq_class & mpq_class::fun(signed char c)        \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) c);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(unsigned char c)      \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) c);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(signed int i)         \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) i);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(unsigned int i)       \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) i);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(signed short int s)   \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) s);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(unsigned short int s) \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) s);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(signed long int l)    \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(unsigned long int l)  \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(float f)              \
{                                                       \
  eval_fun::eval(mp, mp, (double) f);                   \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class & mpq_class::fun(double d)             \
{                                                       \
  eval_fun::eval(mp, mp, d);                            \
  return *this;                                         \
}                                                       \
                                                        \
/*                                                      \
inline mpq_class & mpq_class::fun(long double ld)       \
{                                                       \
  eval_fun::eval(mp, mp, ld);                           \
  return *this;                                         \
} */

#define __GMPQ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
__GMPQQ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)        \
__GMPQN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)

#define __GMPQ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \
                                                          \
inline mpq_class & mpq_class::fun(unsigned long int l)    \
{                                                         \
  eval_fun::eval(mp, mp, l);                              \
  return *this;                                           \
}

#define __GMPQ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \
                                                        \
inline mpq_class & mpq_class::fun()                     \
{                                                       \
  eval_fun::eval(mp, mp);                               \
  return *this;                                         \
}                                                       \
                                                        \
inline mpq_class mpq_class::fun(int)                    \
{                                                       \
  mpq_class temp(*this);                                \
  eval_fun::eval(mp, mp);                               \
  return temp;                                          \
}


// member operators for mpf_class

#define __GMPFF_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)         \
                                                                \
template <class T, class U>                                     \
inline mpf_class & mpf_class::fun(const __gmp_expr<T, U> &expr) \
{                                                               \
  __gmpf_temp temp(expr, get_prec());                           \
  eval_fun::eval(mp, mp, temp.get_mp());                        \
  return *this;                                                 \
}

#define __GMPFN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
                                                        \
inline mpf_class & mpf_class::fun(signed char c)        \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) c);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(unsigned char c)      \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) c);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(signed int i)         \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) i);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(unsigned int i)       \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) i);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(signed short int s)   \
{                                                       \
  eval_fun::eval(mp, mp, (signed long int) s);          \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(unsigned short int s) \
{                                                       \
  eval_fun::eval(mp, mp, (unsigned long int) s);        \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(signed long int l)    \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(unsigned long int l)  \
{                                                       \
  eval_fun::eval(mp, mp, l);                            \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(float f)              \
{                                                       \
  eval_fun::eval(mp, mp, (double) f);                   \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class & mpf_class::fun(double d)             \
{                                                       \
  eval_fun::eval(mp, mp, d);                            \
  return *this;                                         \
}                                                       \
                                                        \
/*                                                      \
inline mpf_class & mpf_class::fun(long double ld)       \
{                                                       \
  eval_fun::eval(mp, mp, ld);                           \
  return *this;                                         \
} */

#define __GMPF_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \
__GMPFF_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)        \
__GMPFN_DEFINE_COMPOUND_OPERATOR(fun, eval_fun)

#define __GMPF_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \
                                                          \
inline mpf_class & mpf_class::fun(unsigned long int l)    \
{                                                         \
  eval_fun::eval(mp, mp, l);                              \
  return *this;                                           \
}

#define __GMPF_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \
                                                        \
inline mpf_class & mpf_class::fun()                     \
{                                                       \
  eval_fun::eval(mp, mp);                               \
  return *this;                                         \
}                                                       \
                                                        \
inline mpf_class mpf_class::fun(int)                    \
{                                                       \
  mpf_class temp(*this);                                \
  eval_fun::eval(mp, mp);                               \
  return temp;                                          \
}


/**************** Arithmetic operators and functions ****************/

// non-member operators and functions

__GMP_DEFINE_UNARY_FUNCTION(operator+, __gmp_unary_plus)
__GMP_DEFINE_UNARY_FUNCTION(operator-, __gmp_unary_minus)
__GMP_DEFINE_UNARY_FUNCTION(operator~, __gmp_unary_com)

__GMP_DEFINE_BINARY_FUNCTION(operator+, __gmp_binary_plus)
__GMP_DEFINE_BINARY_FUNCTION(operator-, __gmp_binary_minus)
__GMP_DEFINE_BINARY_FUNCTION(operator*, __gmp_binary_multiplies)
__GMP_DEFINE_BINARY_FUNCTION(operator/, __gmp_binary_divides)
__GMP_DEFINE_BINARY_FUNCTION(operator%, __gmp_binary_modulus)
__GMP_DEFINE_BINARY_FUNCTION(operator&, __gmp_binary_and)
__GMP_DEFINE_BINARY_FUNCTION(operator|, __gmp_binary_ior)
__GMP_DEFINE_BINARY_FUNCTION(operator^, __gmp_binary_xor)

__GMP_DEFINE_BINARY_FUNCTION_UI(operator<<, __gmp_binary_lshift)
__GMP_DEFINE_BINARY_FUNCTION_UI(operator>>, __gmp_binary_rshift)

__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator==, __gmp_binary_equal)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator!=, __gmp_binary_not_equal)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<, __gmp_binary_less)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<=, __gmp_binary_less_equal)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>, __gmp_binary_greater)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>=, \
                                  __gmp_binary_greater_equal)

__GMP_DEFINE_UNARY_FUNCTION(abs, __gmp_abs_function)
__GMP_DEFINE_UNARY_FUNCTION(trunc, __gmp_trunc_function)
__GMP_DEFINE_UNARY_FUNCTION(floor, __gmp_floor_function)
__GMP_DEFINE_UNARY_FUNCTION(ceil, __gmp_ceil_function)
__GMP_DEFINE_UNARY_FUNCTION(sqrt, __gmp_sqrt_function)
__GMP_DEFINE_BINARY_FUNCTION(hypot, __gmp_hypot_function)

__GMP_DEFINE_UNARY_TYPE_FUNCTION(int, sgn, __gmp_sgn_function)
__GMP_DEFINE_BINARY_TYPE_FUNCTION(int, cmp, __gmp_cmp_function)

// member operators for mpz_class

__GMPZ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus)
__GMPZ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus)
__GMPZ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies)
__GMPZ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides)
__GMPZ_DEFINE_COMPOUND_OPERATOR(operator%=, __gmp_binary_modulus)

__GMPZZ_DEFINE_COMPOUND_OPERATOR(operator&=, __gmp_binary_and)
__GMPZZ_DEFINE_COMPOUND_OPERATOR(operator|=, __gmp_binary_ior)
__GMPZZ_DEFINE_COMPOUND_OPERATOR(operator^=, __gmp_binary_xor)

__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift)
__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift)

__GMPZ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment)
__GMPZ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement)

// member operators for mpz_classref

__GMPZR_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus)
__GMPZR_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus)
__GMPZR_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies)
__GMPZR_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides)
__GMPZR_DEFINE_COMPOUND_OPERATOR(operator%=, __gmp_binary_modulus)

__GMPZRR_DEFINE_COMPOUND_OPERATOR(operator&=, __gmp_binary_and)
__GMPZRR_DEFINE_COMPOUND_OPERATOR(operator|=, __gmp_binary_ior)
__GMPZRR_DEFINE_COMPOUND_OPERATOR(operator^=, __gmp_binary_xor)

__GMPZR_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift)
__GMPZR_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift)

__GMPZR_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment)
__GMPZR_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement)

// member operators for mpq_class

__GMPQ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus)
__GMPQ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus)
__GMPQ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies)
__GMPQ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides)

__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift)
__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift)

__GMPQ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment)
__GMPQ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement)

// member operators for mpf_class

__GMPF_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus)
__GMPF_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus)
__GMPF_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies)
__GMPF_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides)

__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift)
__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift)

__GMPF_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment)
__GMPF_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement)


/**************** Class wrapper for gmp_randstate_t ****************/

class __gmp_urandomb_value { };
class __gmp_urandomm_value { };

template <>
class __gmp_expr<__gmpz_value, __gmp_urandomb_value>
{
private:
  __gmp_randstate_struct *state;
  unsigned long int bits;
public:
  __gmp_expr(gmp_randstate_t s, unsigned long int l) : state(s), bits(l) { }
  void eval(mpz_ptr z) const { __gmp_rand_function::eval(z, state, bits); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <>
class __gmp_expr<__gmpz_value, __gmp_urandomm_value>
{
private:
  __gmp_randstate_struct *state;
  mpz_class range;
public:
  __gmp_expr(gmp_randstate_t s, const mpz_class &z) : state(s), range(z) { }
  void eval(mpz_ptr z) const
  { __gmp_rand_function::eval(z, state, range.get_mpz_t()); }
  unsigned long int get_prec() const { return mpf_get_default_prec(); }
};

template <>
class __gmp_expr<__gmpf_value, __gmp_urandomb_value>
{
private:
  __gmp_randstate_struct *state;
  unsigned long int bits;
public:
  __gmp_expr(gmp_randstate_t s, unsigned long int l) : state(s), bits(l) { }
  void eval(mpf_ptr f, unsigned long int prec) const
  { __gmp_rand_function::eval(f, state, (bits>0) ? get_prec() : prec); }
  unsigned long int get_prec() const
  {
    if (bits == 0)
      return mpf_get_default_prec();
    else
      return bits;
  }
};

extern "C" {
  typedef void __gmp_randinit_default_t (gmp_randstate_t);
  typedef void __gmp_randinit_lc_2exp_t (gmp_randstate_t, mpz_srcptr, unsigned 
long int, unsigned long int);
  typedef int __gmp_randinit_lc_2exp_size_t (gmp_randstate_t, unsigned long 
int);
}

class gmp_randclass
{
private:
  gmp_randstate_t state;
  gmp_randclass(const gmp_randclass &);  // copy constructor not allowed
  void operator=(const gmp_randclass &); // copying with assignment not allowed
public:
  // constructors and destructor
  gmp_randclass(gmp_randalg_t alg, unsigned long int size)
  {
    switch (alg)
      {
      case GMP_RAND_ALG_LC: // no other cases for now
      default:
        gmp_randinit(state, alg, size);
        break;
      }
  }

  // gmp_randinit_default
  gmp_randclass(__gmp_randinit_default_t* f)
  { f(state); }

  // gmp_randinit_lc_2exp
  gmp_randclass(__gmp_randinit_lc_2exp_t* f,
                mpz_class z, unsigned long int l1, unsigned long int l2)
  { f(state, z.get_mpz_t(), l1, l2); }

  // gmp_randinit_lc_2exp_size
  gmp_randclass(__gmp_randinit_lc_2exp_size_t* f,
                unsigned long int size)
  { f(state, size); }

  ~gmp_randclass() { gmp_randclear(state); }

  // initialize
  void seed(); // choose a random seed some way (?)
  void seed(unsigned long int s) { gmp_randseed_ui(state, s); }
  void seed(const mpz_class &z) { gmp_randseed(state, z.get_mpz_t()); }

  // get random number
  __gmp_expr<__gmpz_value, __gmp_urandomb_value>
  get_z_bits(unsigned long int l)
  { return __gmp_expr<__gmpz_value, __gmp_urandomb_value>(state, l); }
  __gmp_expr<__gmpz_value, __gmp_urandomb_value>
  get_z_bits(const mpz_class &z)
  { return get_z_bits(z.get_ui()); }

  __gmp_expr<__gmpz_value, __gmp_urandomm_value>
  get_z_range(const mpz_class &z)
  { return __gmp_expr<__gmpz_value, __gmp_urandomm_value>(state, z); }
  __gmp_expr<__gmpf_value, __gmp_urandomb_value>
  get_f(unsigned long int prec = 0)
  { return __gmp_expr<__gmpf_value, __gmp_urandomb_value>(state, prec); }
};


/**************** #undef all private macros ****************/

#undef __GMPZQ_DEFINE_EXPR

#undef __GMP_DEFINE_UNARY_FUNCTION
#undef __GMP_DEFINE_BINARY_FUNCTION
#undef __GMP_DEFINE_BINARY_FUNCTION_UI
#undef __GMP_DEFINE_UNARY_TYPE_FUNCTION
#undef __GMP_DEFINE_BINARY_TYPE_FUNCTION

#undef __GMPZZ_DECLARE_COMPOUND_OPERATOR
#undef __GMPZN_DECLARE_COMPOUND_OPERATOR
#undef __GMPZ_DECLARE_COMPOUND_OPERATOR
#undef __GMPZ_DECLARE_COMPOUND_OPERATOR_UI
#undef __GMPZ_DECLARE_INCREMENT_OPERATOR

#undef __GMPZZ_DEFINE_COMPOUND_OPERATOR
#undef __GMPZN_DEFINE_COMPOUND_OPERATOR
#undef __GMPZ_DEFINE_COMPOUND_OPERATOR
#undef __GMPZ_DEFINE_COMPOUND_OPERATOR_UI
#undef __GMPZ_DEFINE_INCREMENT_OPERATOR

#undef __GMPZRR_DECLARE_COMPOUND_OPERATOR
#undef __GMPZRN_DECLARE_COMPOUND_OPERATOR
#undef __GMPZR_DECLARE_COMPOUND_OPERATOR
#undef __GMPZR_DECLARE_COMPOUND_OPERATOR_UI
#undef __GMPZR_DECLARE_INCREMENT_OPERATOR

#undef __GMPZRR_DEFINE_COMPOUND_OPERATOR
#undef __GMPZRN_DEFINE_COMPOUND_OPERATOR
#undef __GMPZR_DEFINE_COMPOUND_OPERATOR
#undef __GMPZR_DEFINE_COMPOUND_OPERATOR_UI
#undef __GMPZR_DEFINE_INCREMENT_OPERATOR

#undef __GMPQQ_DECLARE_COMPOUND_OPERATOR
#undef __GMPQN_DECLARE_COMPOUND_OPERATOR
#undef __GMPQ_DECLARE_COMPOUND_OPERATOR
#undef __GMPQ_DECLARE_COMPOUND_OPERATOR_UI
#undef __GMPQ_DECLARE_INCREMENT_OPERATOR

#undef __GMPQQ_DEFINE_COMPOUND_OPERATOR
#undef __GMPQN_DEFINE_COMPOUND_OPERATOR
#undef __GMPQ_DEFINE_COMPOUND_OPERATOR
#undef __GMPQ_DEFINE_COMPOUND_OPERATOR_UI
#undef __GMPQ_DEFINE_INCREMENT_OPERATOR

#undef __GMPFF_DECLARE_COMPOUND_OPERATOR
#undef __GMPFN_DECLARE_COMPOUND_OPERATOR
#undef __GMPF_DECLARE_COMPOUND_OPERATOR
#undef __GMPF_DECLARE_COMPOUND_OPERATOR_UI
#undef __GMPF_DECLARE_INCREMENT_OPERATOR

#undef __GMPFF_DEFINE_COMPOUND_OPERATOR
#undef __GMPFN_DEFINE_COMPOUND_OPERATOR
#undef __GMPF_DEFINE_COMPOUND_OPERATOR
#undef __GMPF_DEFINE_COMPOUND_OPERATOR_UI
#undef __GMPF_DEFINE_INCREMENT_OPERATOR


#endif /* __GMP_PLUSPLUS__ */
// main.cpp
#include <gmp.h>
#include <gmpxx.h>

int main()
{
    mpf_class mpf;

    return 0;
}
// main2.cpp
#include <gmp.h>
#include <gmpxx.h>
#include <string>

int main()
{
    mpf_class mpf;
    std::string str;

    mpf = str;

    return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]