lemon-project-template-glpk
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/deps/glpk/src/glpgmp.h Sun Nov 06 20:59:10 2011 +0100 1.3 @@ -0,0 +1,190 @@ 1.4 +/* glpgmp.h (bignum arithmetic) */ 1.5 + 1.6 +/*********************************************************************** 1.7 +* This code is part of GLPK (GNU Linear Programming Kit). 1.8 +* 1.9 +* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 1.10 +* 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics, 1.11 +* Moscow Aviation Institute, Moscow, Russia. All rights reserved. 1.12 +* E-mail: <mao@gnu.org>. 1.13 +* 1.14 +* GLPK is free software: you can redistribute it and/or modify it 1.15 +* under the terms of the GNU General Public License as published by 1.16 +* the Free Software Foundation, either version 3 of the License, or 1.17 +* (at your option) any later version. 1.18 +* 1.19 +* GLPK is distributed in the hope that it will be useful, but WITHOUT 1.20 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 1.21 +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 1.22 +* License for more details. 1.23 +* 1.24 +* You should have received a copy of the GNU General Public License 1.25 +* along with GLPK. If not, see <http://www.gnu.org/licenses/>. 1.26 +***********************************************************************/ 1.27 + 1.28 +#ifndef GLPGMP_H 1.29 +#define GLPGMP_H 1.30 + 1.31 +#ifdef HAVE_CONFIG_H 1.32 +#include <config.h> 1.33 +#endif 1.34 + 1.35 +#ifdef HAVE_GMP /* use GNU MP bignum library */ 1.36 + 1.37 +#include <gmp.h> 1.38 + 1.39 +#define gmp_pool_count _glp_gmp_pool_count 1.40 +#define gmp_free_mem _glp_gmp_free_mem 1.41 + 1.42 +int gmp_pool_count(void); 1.43 +void gmp_free_mem(void); 1.44 + 1.45 +#else /* use GLPK bignum module */ 1.46 + 1.47 +/*---------------------------------------------------------------------- 1.48 +// INTEGER NUMBERS 1.49 +// 1.50 +// Depending on its magnitude an integer number of arbitrary precision 1.51 +// is represented either in short format or in long format. 1.52 +// 1.53 +// Short format corresponds to the int type and allows representing 1.54 +// integer numbers in the range [-(2^31-1), +(2^31-1)]. Note that for 1.55 +// the most negative number of int type the short format is not used. 1.56 +// 1.57 +// In long format integer numbers are represented using the positional 1.58 +// system with the base (radix) 2^16 = 65536: 1.59 +// 1.60 +// x = (-1)^s sum{j in 0..n-1} d[j] * 65536^j, 1.61 +// 1.62 +// where x is the integer to be represented, s is its sign (+1 or -1), 1.63 +// d[j] are its digits (0 <= d[j] <= 65535). 1.64 +// 1.65 +// RATIONAL NUMBERS 1.66 +// 1.67 +// A rational number is represented as an irreducible fraction: 1.68 +// 1.69 +// p / q, 1.70 +// 1.71 +// where p (numerator) and q (denominator) are integer numbers (q > 0) 1.72 +// having no common divisors. */ 1.73 + 1.74 +struct mpz 1.75 +{ /* integer number */ 1.76 + int val; 1.77 + /* if ptr is a null pointer, the number is in short format, and 1.78 + val is its value; otherwise, the number is in long format, and 1.79 + val is its sign (+1 or -1) */ 1.80 + struct mpz_seg *ptr; 1.81 + /* pointer to the linked list of the number segments ordered in 1.82 + ascending of powers of the base */ 1.83 +}; 1.84 + 1.85 +struct mpz_seg 1.86 +{ /* integer number segment */ 1.87 + unsigned short d[6]; 1.88 + /* six digits of the number ordered in ascending of powers of the 1.89 + base */ 1.90 + struct mpz_seg *next; 1.91 + /* pointer to the next number segment */ 1.92 +}; 1.93 + 1.94 +struct mpq 1.95 +{ /* rational number (p / q) */ 1.96 + struct mpz p; 1.97 + /* numerator */ 1.98 + struct mpz q; 1.99 + /* denominator */ 1.100 +}; 1.101 + 1.102 +typedef struct mpz *mpz_t; 1.103 +typedef struct mpq *mpq_t; 1.104 + 1.105 +#define gmp_get_atom _glp_gmp_get_atom 1.106 +#define gmp_free_atom _glp_gmp_free_atom 1.107 +#define gmp_pool_count _glp_gmp_pool_count 1.108 +#define gmp_get_work _glp_gmp_get_work 1.109 +#define gmp_free_mem _glp_gmp_free_mem 1.110 + 1.111 +#define _mpz_init _glp_mpz_init 1.112 +#define mpz_clear _glp_mpz_clear 1.113 +#define mpz_set _glp_mpz_set 1.114 +#define mpz_set_si _glp_mpz_set_si 1.115 +#define mpz_get_d _glp_mpz_get_d 1.116 +#define mpz_get_d_2exp _glp_mpz_get_d_2exp 1.117 +#define mpz_swap _glp_mpz_swap 1.118 +#define mpz_add _glp_mpz_add 1.119 +#define mpz_sub _glp_mpz_sub 1.120 +#define mpz_mul _glp_mpz_mul 1.121 +#define mpz_neg _glp_mpz_neg 1.122 +#define mpz_abs _glp_mpz_abs 1.123 +#define mpz_div _glp_mpz_div 1.124 +#define mpz_gcd _glp_mpz_gcd 1.125 +#define mpz_cmp _glp_mpz_cmp 1.126 +#define mpz_sgn _glp_mpz_sgn 1.127 +#define mpz_out_str _glp_mpz_out_str 1.128 + 1.129 +#define _mpq_init _glp_mpq_init 1.130 +#define mpq_clear _glp_mpq_clear 1.131 +#define mpq_canonicalize _glp_mpq_canonicalize 1.132 +#define mpq_set _glp_mpq_set 1.133 +#define mpq_set_si _glp_mpq_set_si 1.134 +#define mpq_get_d _glp_mpq_get_d 1.135 +#define mpq_set_d _glp_mpq_set_d 1.136 +#define mpq_add _glp_mpq_add 1.137 +#define mpq_sub _glp_mpq_sub 1.138 +#define mpq_mul _glp_mpq_mul 1.139 +#define mpq_div _glp_mpq_div 1.140 +#define mpq_neg _glp_mpq_neg 1.141 +#define mpq_abs _glp_mpq_abs 1.142 +#define mpq_cmp _glp_mpq_cmp 1.143 +#define mpq_sgn _glp_mpq_sgn 1.144 +#define mpq_out_str _glp_mpq_out_str 1.145 + 1.146 +void *gmp_get_atom(int size); 1.147 +void gmp_free_atom(void *ptr, int size); 1.148 +int gmp_pool_count(void); 1.149 +unsigned short *gmp_get_work(int size); 1.150 +void gmp_free_mem(void); 1.151 + 1.152 +mpz_t _mpz_init(void); 1.153 +#define mpz_init(x) (void)((x) = _mpz_init()) 1.154 +void mpz_clear(mpz_t x); 1.155 +void mpz_set(mpz_t z, mpz_t x); 1.156 +void mpz_set_si(mpz_t x, int val); 1.157 +double mpz_get_d(mpz_t x); 1.158 +double mpz_get_d_2exp(int *exp, mpz_t x); 1.159 +void mpz_swap(mpz_t x, mpz_t y); 1.160 +void mpz_add(mpz_t, mpz_t, mpz_t); 1.161 +void mpz_sub(mpz_t, mpz_t, mpz_t); 1.162 +void mpz_mul(mpz_t, mpz_t, mpz_t); 1.163 +void mpz_neg(mpz_t z, mpz_t x); 1.164 +void mpz_abs(mpz_t z, mpz_t x); 1.165 +void mpz_div(mpz_t q, mpz_t r, mpz_t x, mpz_t y); 1.166 +void mpz_gcd(mpz_t z, mpz_t x, mpz_t y); 1.167 +int mpz_cmp(mpz_t x, mpz_t y); 1.168 +int mpz_sgn(mpz_t x); 1.169 +int mpz_out_str(void *fp, int base, mpz_t x); 1.170 + 1.171 +mpq_t _mpq_init(void); 1.172 +#define mpq_init(x) (void)((x) = _mpq_init()) 1.173 +void mpq_clear(mpq_t x); 1.174 +void mpq_canonicalize(mpq_t x); 1.175 +void mpq_set(mpq_t z, mpq_t x); 1.176 +void mpq_set_si(mpq_t x, int p, unsigned int q); 1.177 +double mpq_get_d(mpq_t x); 1.178 +void mpq_set_d(mpq_t x, double val); 1.179 +void mpq_add(mpq_t z, mpq_t x, mpq_t y); 1.180 +void mpq_sub(mpq_t z, mpq_t x, mpq_t y); 1.181 +void mpq_mul(mpq_t z, mpq_t x, mpq_t y); 1.182 +void mpq_div(mpq_t z, mpq_t x, mpq_t y); 1.183 +void mpq_neg(mpq_t z, mpq_t x); 1.184 +void mpq_abs(mpq_t z, mpq_t x); 1.185 +int mpq_cmp(mpq_t x, mpq_t y); 1.186 +int mpq_sgn(mpq_t x); 1.187 +int mpq_out_str(void *fp, int base, mpq_t x); 1.188 + 1.189 +#endif 1.190 + 1.191 +#endif 1.192 + 1.193 +/* eof */