lemon-project-template-glpk

annotate deps/glpk/src/glpgmp.h @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
rev   line source
alpar@9 1 /* glpgmp.h (bignum arithmetic) */
alpar@9 2
alpar@9 3 /***********************************************************************
alpar@9 4 * This code is part of GLPK (GNU Linear Programming Kit).
alpar@9 5 *
alpar@9 6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@9 7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
alpar@9 8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@9 9 * E-mail: <mao@gnu.org>.
alpar@9 10 *
alpar@9 11 * GLPK is free software: you can redistribute it and/or modify it
alpar@9 12 * under the terms of the GNU General Public License as published by
alpar@9 13 * the Free Software Foundation, either version 3 of the License, or
alpar@9 14 * (at your option) any later version.
alpar@9 15 *
alpar@9 16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@9 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@9 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@9 19 * License for more details.
alpar@9 20 *
alpar@9 21 * You should have received a copy of the GNU General Public License
alpar@9 22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@9 23 ***********************************************************************/
alpar@9 24
alpar@9 25 #ifndef GLPGMP_H
alpar@9 26 #define GLPGMP_H
alpar@9 27
alpar@9 28 #ifdef HAVE_CONFIG_H
alpar@9 29 #include <config.h>
alpar@9 30 #endif
alpar@9 31
alpar@9 32 #ifdef HAVE_GMP /* use GNU MP bignum library */
alpar@9 33
alpar@9 34 #include <gmp.h>
alpar@9 35
alpar@9 36 #define gmp_pool_count _glp_gmp_pool_count
alpar@9 37 #define gmp_free_mem _glp_gmp_free_mem
alpar@9 38
alpar@9 39 int gmp_pool_count(void);
alpar@9 40 void gmp_free_mem(void);
alpar@9 41
alpar@9 42 #else /* use GLPK bignum module */
alpar@9 43
alpar@9 44 /*----------------------------------------------------------------------
alpar@9 45 // INTEGER NUMBERS
alpar@9 46 //
alpar@9 47 // Depending on its magnitude an integer number of arbitrary precision
alpar@9 48 // is represented either in short format or in long format.
alpar@9 49 //
alpar@9 50 // Short format corresponds to the int type and allows representing
alpar@9 51 // integer numbers in the range [-(2^31-1), +(2^31-1)]. Note that for
alpar@9 52 // the most negative number of int type the short format is not used.
alpar@9 53 //
alpar@9 54 // In long format integer numbers are represented using the positional
alpar@9 55 // system with the base (radix) 2^16 = 65536:
alpar@9 56 //
alpar@9 57 // x = (-1)^s sum{j in 0..n-1} d[j] * 65536^j,
alpar@9 58 //
alpar@9 59 // where x is the integer to be represented, s is its sign (+1 or -1),
alpar@9 60 // d[j] are its digits (0 <= d[j] <= 65535).
alpar@9 61 //
alpar@9 62 // RATIONAL NUMBERS
alpar@9 63 //
alpar@9 64 // A rational number is represented as an irreducible fraction:
alpar@9 65 //
alpar@9 66 // p / q,
alpar@9 67 //
alpar@9 68 // where p (numerator) and q (denominator) are integer numbers (q > 0)
alpar@9 69 // having no common divisors. */
alpar@9 70
alpar@9 71 struct mpz
alpar@9 72 { /* integer number */
alpar@9 73 int val;
alpar@9 74 /* if ptr is a null pointer, the number is in short format, and
alpar@9 75 val is its value; otherwise, the number is in long format, and
alpar@9 76 val is its sign (+1 or -1) */
alpar@9 77 struct mpz_seg *ptr;
alpar@9 78 /* pointer to the linked list of the number segments ordered in
alpar@9 79 ascending of powers of the base */
alpar@9 80 };
alpar@9 81
alpar@9 82 struct mpz_seg
alpar@9 83 { /* integer number segment */
alpar@9 84 unsigned short d[6];
alpar@9 85 /* six digits of the number ordered in ascending of powers of the
alpar@9 86 base */
alpar@9 87 struct mpz_seg *next;
alpar@9 88 /* pointer to the next number segment */
alpar@9 89 };
alpar@9 90
alpar@9 91 struct mpq
alpar@9 92 { /* rational number (p / q) */
alpar@9 93 struct mpz p;
alpar@9 94 /* numerator */
alpar@9 95 struct mpz q;
alpar@9 96 /* denominator */
alpar@9 97 };
alpar@9 98
alpar@9 99 typedef struct mpz *mpz_t;
alpar@9 100 typedef struct mpq *mpq_t;
alpar@9 101
alpar@9 102 #define gmp_get_atom _glp_gmp_get_atom
alpar@9 103 #define gmp_free_atom _glp_gmp_free_atom
alpar@9 104 #define gmp_pool_count _glp_gmp_pool_count
alpar@9 105 #define gmp_get_work _glp_gmp_get_work
alpar@9 106 #define gmp_free_mem _glp_gmp_free_mem
alpar@9 107
alpar@9 108 #define _mpz_init _glp_mpz_init
alpar@9 109 #define mpz_clear _glp_mpz_clear
alpar@9 110 #define mpz_set _glp_mpz_set
alpar@9 111 #define mpz_set_si _glp_mpz_set_si
alpar@9 112 #define mpz_get_d _glp_mpz_get_d
alpar@9 113 #define mpz_get_d_2exp _glp_mpz_get_d_2exp
alpar@9 114 #define mpz_swap _glp_mpz_swap
alpar@9 115 #define mpz_add _glp_mpz_add
alpar@9 116 #define mpz_sub _glp_mpz_sub
alpar@9 117 #define mpz_mul _glp_mpz_mul
alpar@9 118 #define mpz_neg _glp_mpz_neg
alpar@9 119 #define mpz_abs _glp_mpz_abs
alpar@9 120 #define mpz_div _glp_mpz_div
alpar@9 121 #define mpz_gcd _glp_mpz_gcd
alpar@9 122 #define mpz_cmp _glp_mpz_cmp
alpar@9 123 #define mpz_sgn _glp_mpz_sgn
alpar@9 124 #define mpz_out_str _glp_mpz_out_str
alpar@9 125
alpar@9 126 #define _mpq_init _glp_mpq_init
alpar@9 127 #define mpq_clear _glp_mpq_clear
alpar@9 128 #define mpq_canonicalize _glp_mpq_canonicalize
alpar@9 129 #define mpq_set _glp_mpq_set
alpar@9 130 #define mpq_set_si _glp_mpq_set_si
alpar@9 131 #define mpq_get_d _glp_mpq_get_d
alpar@9 132 #define mpq_set_d _glp_mpq_set_d
alpar@9 133 #define mpq_add _glp_mpq_add
alpar@9 134 #define mpq_sub _glp_mpq_sub
alpar@9 135 #define mpq_mul _glp_mpq_mul
alpar@9 136 #define mpq_div _glp_mpq_div
alpar@9 137 #define mpq_neg _glp_mpq_neg
alpar@9 138 #define mpq_abs _glp_mpq_abs
alpar@9 139 #define mpq_cmp _glp_mpq_cmp
alpar@9 140 #define mpq_sgn _glp_mpq_sgn
alpar@9 141 #define mpq_out_str _glp_mpq_out_str
alpar@9 142
alpar@9 143 void *gmp_get_atom(int size);
alpar@9 144 void gmp_free_atom(void *ptr, int size);
alpar@9 145 int gmp_pool_count(void);
alpar@9 146 unsigned short *gmp_get_work(int size);
alpar@9 147 void gmp_free_mem(void);
alpar@9 148
alpar@9 149 mpz_t _mpz_init(void);
alpar@9 150 #define mpz_init(x) (void)((x) = _mpz_init())
alpar@9 151 void mpz_clear(mpz_t x);
alpar@9 152 void mpz_set(mpz_t z, mpz_t x);
alpar@9 153 void mpz_set_si(mpz_t x, int val);
alpar@9 154 double mpz_get_d(mpz_t x);
alpar@9 155 double mpz_get_d_2exp(int *exp, mpz_t x);
alpar@9 156 void mpz_swap(mpz_t x, mpz_t y);
alpar@9 157 void mpz_add(mpz_t, mpz_t, mpz_t);
alpar@9 158 void mpz_sub(mpz_t, mpz_t, mpz_t);
alpar@9 159 void mpz_mul(mpz_t, mpz_t, mpz_t);
alpar@9 160 void mpz_neg(mpz_t z, mpz_t x);
alpar@9 161 void mpz_abs(mpz_t z, mpz_t x);
alpar@9 162 void mpz_div(mpz_t q, mpz_t r, mpz_t x, mpz_t y);
alpar@9 163 void mpz_gcd(mpz_t z, mpz_t x, mpz_t y);
alpar@9 164 int mpz_cmp(mpz_t x, mpz_t y);
alpar@9 165 int mpz_sgn(mpz_t x);
alpar@9 166 int mpz_out_str(void *fp, int base, mpz_t x);
alpar@9 167
alpar@9 168 mpq_t _mpq_init(void);
alpar@9 169 #define mpq_init(x) (void)((x) = _mpq_init())
alpar@9 170 void mpq_clear(mpq_t x);
alpar@9 171 void mpq_canonicalize(mpq_t x);
alpar@9 172 void mpq_set(mpq_t z, mpq_t x);
alpar@9 173 void mpq_set_si(mpq_t x, int p, unsigned int q);
alpar@9 174 double mpq_get_d(mpq_t x);
alpar@9 175 void mpq_set_d(mpq_t x, double val);
alpar@9 176 void mpq_add(mpq_t z, mpq_t x, mpq_t y);
alpar@9 177 void mpq_sub(mpq_t z, mpq_t x, mpq_t y);
alpar@9 178 void mpq_mul(mpq_t z, mpq_t x, mpq_t y);
alpar@9 179 void mpq_div(mpq_t z, mpq_t x, mpq_t y);
alpar@9 180 void mpq_neg(mpq_t z, mpq_t x);
alpar@9 181 void mpq_abs(mpq_t z, mpq_t x);
alpar@9 182 int mpq_cmp(mpq_t x, mpq_t y);
alpar@9 183 int mpq_sgn(mpq_t x);
alpar@9 184 int mpq_out_str(void *fp, int base, mpq_t x);
alpar@9 185
alpar@9 186 #endif
alpar@9 187
alpar@9 188 #endif
alpar@9 189
alpar@9 190 /* eof */