00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_GMP_HPP
00014 #define __MMX_GMP_HPP
00015 #include <gmp.h>
00016 #include <basix/port.hpp>
00017
00018 namespace mmx {
00019
00020 #if GMP_NAIL_BITS != 0
00021 #error "GMP uses nail bits -- sorry, but this is not supported in Mathemagix"
00022 #endif
00023 #define BITS_PER_LIMB GMP_LIMB_BITS
00024 #define DEFAULT_LOW GMP_LIMB_BITS
00025
00026 extern gmp_randstate_t gmp_randstate;
00027
00028 inline void mpz_add_si (mpz_t dest, const mpz_t arg, long int plus) {
00029 if (plus >= 0) mpz_add_ui (dest, arg, plus);
00030 else mpz_sub_ui (dest, arg, -plus); }
00031 inline void mpz_sub_si (mpz_t dest, const mpz_t arg, long int plus) {
00032 if (plus >= 0) mpz_sub_ui (dest, arg, plus);
00033 else mpz_add_ui (dest, arg, -plus); }
00034 inline void mpz_si_sub (mpz_t dest, long int plus, const mpz_t arg) {
00035 if (plus >= 0) mpz_ui_sub (dest, plus, arg);
00036 else { mpz_add_ui (dest, arg, -plus); mpz_neg (dest, dest); } }
00037 inline void mpz_mul_2si (mpz_t dest, const mpz_t arg, long int shift) {
00038 if (shift >= 0) mpz_mul_2exp (dest, arg, shift);
00039 else mpz_fdiv_q_2exp (dest, arg, -shift); }
00040 inline void mpq_mul_2si (mpq_t dest, const mpq_t arg, long int shift) {
00041 if (shift >= 0) mpq_mul_2exp (dest, arg, shift);
00042 else mpq_div_2exp (dest, arg, -shift); }
00043
00044 void mpz_binary_write (const port& p, const mpz_t arg);
00045 void mpz_binary_read (const port& p, mpz_t dest);
00046
00047 }
00048 #endif // __MMX_GMP_HPP