1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/* cddmp.c (cddlib arithmetic operations using gmp)
written by Komei Fukuda, fukuda@math.ethz.ch
Version 0.94i, March 9, 2018
*/
/* This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "setoper.h" /* set operation library header (Ver. March 16,1995 or later) */
#include "cdd.h"
void dd_set_global_constants()
{
dd_init(dd_zero);
dd_init(dd_minuszero);
dd_init(dd_one);
dd_init(dd_minusone);
dd_init(dd_purezero);
time(&dd_statStartTime); /* cddlib starting time */
dd_statBApivots=0; /* basis finding pivots */
dd_statCCpivots=0; /* criss-cross pivots */
dd_statDS1pivots=0; /* phase 1 pivots */
dd_statDS2pivots=0; /* phase 2 pivots */
dd_statACpivots=0; /* anticycling (cc) pivots */
dd_choiceLPSolverDefault=dd_DualSimplex; /* Default LP solver Algorithm */
dd_choiceRedcheckAlgorithm=dd_DualSimplex; /* Redundancy Checking Algorithm */
dd_choiceLexicoPivotQ=dd_TRUE; /* whether to use the lexicographic pivot */
#if defined GMPRATIONAL
dd_statBSpivots=0; /* basis status checking pivots */
mpq_set_ui(dd_zero,0U,1U);
mpq_set_ui(dd_purezero,0U,1U);
mpq_set_ui(dd_one,1U,1U);
mpq_set_si(dd_minusone,-1L,1U);
ddf_set_global_constants();
#elif defined GMPFLOAT
mpf_set_d(dd_zero,dd_almostzero);
mpf_set_ui(dd_purezero,0U);
mpf_set_ui(dd_one,1U);
mpf_set_si(dd_minusone,-1L,1U);
#else
dd_zero[0]= dd_almostzero; /*real zero */
dd_purezero[0]= 0.0;
dd_one[0]= 1L;
dd_minusone[0]= -1L;
#endif
dd_neg(dd_minuszero,dd_zero);
}
void dd_free_global_constants()
{
dd_clear(dd_zero);
dd_clear(dd_minuszero);
dd_clear(dd_one);
dd_clear(dd_minusone);
dd_clear(dd_purezero);
time(&dd_statStartTime); /* cddlib starting time */
dd_statBApivots=0; /* basis finding pivots */
dd_statCCpivots=0; /* criss-cross pivots */
dd_statDS1pivots=0; /* phase 1 pivots */
dd_statDS2pivots=0; /* phase 2 pivots */
dd_statACpivots=0; /* anticycling (cc) pivots */
dd_choiceLPSolverDefault=dd_DualSimplex; /* Default LP solver Algorithm */
dd_choiceRedcheckAlgorithm=dd_DualSimplex; /* Redundancy Checking Algorithm */
dd_choiceLexicoPivotQ=dd_TRUE; /* whether to use the lexicographic pivot */
#if defined GMPRATIONAL
dd_statBSpivots=0; /* basis status checking pivots */
ddf_free_global_constants();
#endif
}
#if defined GMPRATIONAL
void ddd_mpq_set_si(mytype a,signed long b)
{
mpz_t nz, dz;
mpz_init(nz); mpz_init(dz);
mpz_set_si(nz, b);
mpz_set_ui(dz, 1U);
mpq_set_num(a, nz);
mpq_set_den(a, dz);
mpz_clear(nz); mpz_clear(dz);
}
#endif
#if defined dd_CDOUBLE
void ddd_init(mytype a)
{
a[0]=0L;
}
void ddd_clear(mytype a)
{
/* a[0]=0L; */
}
void ddd_set(mytype a,mytype b)
{
a[0]=b[0];
}
void ddd_set_d(mytype a,double b)
{
a[0]=b;
}
void ddd_set_si(mytype a,signed long b)
{
a[0]=(double)b;
}
void ddd_set_si2(mytype a,signed long b, unsigned long c)
{
a[0]=(double)b/(double)c;
}
void ddd_add(mytype a,mytype b,mytype c)
{
a[0]=b[0]+c[0];
}
void ddd_sub(mytype a,mytype b,mytype c)
{
a[0]=b[0]-c[0];
}
void ddd_mul(mytype a,mytype b,mytype c)
{
a[0]=b[0]*c[0];
}
void ddd_div(mytype a,mytype b,mytype c)
{
a[0]=b[0]/c[0];
}
void ddd_neg(mytype a,mytype b)
{
a[0]=-b[0];
}
void ddd_inv(mytype a,mytype b)
{
a[0]=1/b[0];
}
int ddd_cmp(mytype a,mytype b)
{
if (a[0]-b[0]>0) return 1;
else if (a[0]-b[0]>=0) return 0;
else return -1;
}
int ddd_sgn(mytype a)
{
if (a[0]>0) return 1;
else if (a[0]>=0) return 0;
else return -1;
}
double ddd_get_d(mytype a)
{
return a[0];
}
#endif
/* end of cddmp.h */
|