File: cddmp_f.c

package info (click to toggle)
cddlib 094h-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,936 kB
  • sloc: sh: 10,179; ansic: 9,555; makefile: 126
file content (186 lines) | stat: -rw-r--r-- 4,402 bytes parent folder | download | duplicates (2)
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
186
/* automatically generated by sed scripts from the c source named below: */
/* cddmp.c       (cddlib arithmetic operations using gmp)
   written by Komei Fukuda, fukuda@math.ethz.ch
   Version 0.94h, April 30, 2015
*/
/* 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_f.h"

void ddf_set_global_constants()
{
 ddf_init(ddf_zero);
 ddf_init(ddf_minuszero);
 ddf_init(ddf_one);
 ddf_init(ddf_minusone);
 ddf_init(ddf_purezero);
  
 time(&ddf_statStartTime); /* cddlib starting time */
 ddf_statBApivots=0;  /* basis finding pivots */
 ddf_statCCpivots=0;  /* criss-cross pivots */
 ddf_statDS1pivots=0; /* phase 1 pivots */
 ddf_statDS2pivots=0; /* phase 2 pivots */
 ddf_statACpivots=0;  /* anticycling (cc) pivots */

 ddf_choiceLPSolverDefault=ddf_DualSimplex;  /* Default LP solver Algorithm */
 ddf_choiceRedcheckAlgorithm=ddf_DualSimplex;  /* Redundancy Checking Algorithm */
 ddf_choiceLexicoPivotQ=ddf_TRUE;    /* whether to use the lexicographic pivot */
 
#if defined ddf_GMPRATIONAL
 ddf_statBSpivots=0;  /* basis status checking pivots */
 mpq_set_ui(ddf_zero,0U,1U);
 mpq_set_ui(ddf_purezero,0U,1U);
 mpq_set_ui(ddf_one,1U,1U);
 mpq_set_si(ddf_minusone,-1L,1U);
 ddf_set_global_constants();
#elif defined GMPFLOAT
 mpf_set_d(ddf_zero,ddf_almostzero);
 mpf_set_ui(ddf_purezero,0U);
 mpf_set_ui(ddf_one,1U);
 mpf_set_si(ddf_minusone,-1L,1U);
#else
 ddf_zero[0]= ddf_almostzero;  /*real zero */
 ddf_purezero[0]= 0.0;
 ddf_one[0]= 1L;
 ddf_minusone[0]= -1L;
#endif
 ddf_neg(ddf_minuszero,ddf_zero);
}

void ddf_free_global_constants()
{
 ddf_clear(ddf_zero);
 ddf_clear(ddf_minuszero);
 ddf_clear(ddf_one);
 ddf_clear(ddf_minusone);
 ddf_clear(ddf_purezero);
  
 time(&ddf_statStartTime); /* cddlib starting time */
 ddf_statBApivots=0;  /* basis finding pivots */
 ddf_statCCpivots=0;  /* criss-cross pivots */
 ddf_statDS1pivots=0; /* phase 1 pivots */
 ddf_statDS2pivots=0; /* phase 2 pivots */
 ddf_statACpivots=0;  /* anticycling (cc) pivots */

 ddf_choiceLPSolverDefault=ddf_DualSimplex;  /* Default LP solver Algorithm */
 ddf_choiceRedcheckAlgorithm=ddf_DualSimplex;  /* Redundancy Checking Algorithm */
 ddf_choiceLexicoPivotQ=ddf_TRUE;    /* whether to use the lexicographic pivot */
 
#if defined ddf_GMPRATIONAL
 ddf_statBSpivots=0;  /* basis status checking pivots */
 ddf_free_global_constants();
#endif
}


#if defined ddf_GMPRATIONAL
void dddf_mpq_set_si(myfloat 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 ddf_ddf_CDOUBLE
void dddf_init(myfloat a)   
{
  a[0]=0L;
}
  
void dddf_clear(myfloat a)
{
  /* a[0]=0L;  */
}

void dddf_set(myfloat a,myfloat b)
{
  a[0]=b[0];
}

void dddf_set_d(myfloat a,double b)
{
  a[0]=b;
}

void dddf_set_si(myfloat a,signed long b)
{
  a[0]=(double)b;
}

void dddf_set_si2(myfloat a,signed long b, unsigned long c)
{
  a[0]=(double)b/(double)c;
}

void dddf_add(myfloat a,myfloat b,myfloat c)
{
  a[0]=b[0]+c[0];
}

void dddf_sub(myfloat a,myfloat b,myfloat c)
{
  a[0]=b[0]-c[0];
}

void dddf_mul(myfloat a,myfloat b,myfloat c)
{
  a[0]=b[0]*c[0];
}

void dddf_div(myfloat a,myfloat b,myfloat c)
{
  a[0]=b[0]/c[0];
}

void dddf_neg(myfloat a,myfloat b)
{
  a[0]=-b[0];
}

void dddf_inv(myfloat a,myfloat b)
{
  a[0]=1/b[0];
}

int dddf_cmp(myfloat a,myfloat b)
{
  if (a[0]-b[0]>0) return 1;
  else if (a[0]-b[0]>=0) return 0;
  else return -1;
}

int dddf_sgn(myfloat a)
{
  if (a[0]>0) return 1;
  else if (a[0]>=0) return 0;
  else return -1;
}

double dddf_get_d(myfloat a)
{
  return a[0];
}
#endif

/* end of  cddmp.h  */