numerix_doc 0.4
/Users/mourrain/Devel/mmx/numerix/include/numerix/mmx_gmp.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : mmx_gmp.hpp
00004 * DESCRIPTION: Interface to gmp
00005 * COPYRIGHT  : (C) 2003  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines