OSMathUtil.h
Go to the documentation of this file.
1 /* $Id: OSMathUtil.h 5284 2017-12-08 13:52:50Z stefan $ */
20 #ifndef MATHUTIL_H
21 #define MATHUTIL_H
22 
23 #include "OSParameters.h"
24 #include "OSdtoa.h"
25 #include "OSErrorClass.h"
26 #include "OSGeneral.h"
27 
28 
29 #include <string>
30 
31 #ifdef __cplusplus
32 extern std::string os_dtoa_format(double x);
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39  double os_strtod_wrap(const char *str, char **strEnd);
40 
41 #ifdef __cplusplus
42 }
43 #endif
44 
57 class MathUtil
58 {
59 public:
60 
62  MathUtil();
63 
65  ~MathUtil();
66 
74  /*public static double round (double x, int precision){
75  double mask = 0.0, y, result;
76  try{
77  mask = Math.pow (10.0, -(double)precision);
78  }
79  catch(ArithmeticException e){
80  return x;
81  }
82  y = mod(x, mask);
83  result = x - y;
84  if (y / mask >= 0.5) result += mask;
85  return result;
86  }//round
87  */
95  /*public static double mod (double x, double y){
96  return x - Math.floor(x / y) * y;
97  }//mod
98  */
99 
117  bool isColumnMajor, int startSize, int valueSize, int* start, int* index,
118  double* value, int dimension);
119 
125  std::string format_os_dtoa( double x);
126 
127 
136  //double os_strtod_wrap(const char *str) throw(ErrorClass);
137 
146  //double os_strtod_wrap(const char *str, const char *strEnd) throw(ErrorClass);
147 
148 
149 
150 };//class MathUtil
151 
152 
168 inline void getMultIncr(int* i, int *mult, int *incr, int size, int defaultIncr)
169 {
170  int k;
171 
172  *mult = 1;
173  *incr = defaultIncr;
174 
175  if (size == 1) return;
176 
177  for (k=1; (k < size) && (i[k] - i[k-1] == defaultIncr); k++)
178  {
179  (*mult)++;
180  }
181  if (*mult > 1 || size == 2) return;
182 
183  *incr = i[1] - i[0];
184  if (i[2] - i[1] != *incr) return;
185 
186  *mult = 3;
187  for (k=3; (k < size) && (i[k] - i[k-1] == *incr); k++)
188  {
189  (*mult)++;
190  }
191  return;
192 }
193 
194 
206 inline void getMultIncr(double* a, int *mult, double *incr, int size)
207 {
208  double mark;
209  int k;
210 
211  *mult = 1;
212  *incr = 0;
213 
214  if (size == 1) return;
215 
216  mark = a[0];
217  for (k=1; (k < size) && (a[k] == mark); k++)
218  {
219  (*mult)++;
220  }
221  if (*mult > 1 || size == 2) return;
222 
223  *incr = a[1] - a[0];
224  if (a[2] - a[1] != *incr) return;
225 
226  *mult = 3;
227  for (k=3; (k < size) && (a[k] - a[k-1] == *incr); k++)
228  {
229  (*mult)++;
230  }
231  return;
232 }
233 
234 
235 
246 inline int getMult(int* i, int size)
247 {
248  int mark;
249 
250  int mult = 1;
251 
252  if (size == 1) return mult;
253 
254  mark = i[0];
255  for (int k=1; (k < size) && (i[k] == mark); k++)
256  {
257  mult++;
258  }
259  return mult;
260 }
261 
262 
263 
274 inline int getMult(double* a, int size)
275 {
276  double mark;
277 
278  int mult = 1;
279 
280  if (size == 1) return mult;
281 
282  mark = a[0];
283  for (int k=1; (k < size) && (a[k] == mark); k++)
284  {
285  mult++;
286  }
287  return mult;
288 }
289 
290 
298 double OSRand();
299 
300 
308 double OSiRand(int iMin, int iMax);
309 
310 #endif
static SparseMatrix * convertLinearConstraintCoefficientMatrixToTheOtherMajor(bool isColumnMajor, int startSize, int valueSize, int *start, int *index, double *value, int dimension)
Round a double number to the precision specified.
Definition: OSMathUtil.cpp:57
void fint fint fint real * a
double OSRand()
OSRand()
Definition: OSMathUtil.cpp:262
double os_strtod_wrap(const char *str, char **strEnd)
Definition: OSMathUtil.cpp:125
~MathUtil()
the class destructor
Definition: OSMathUtil.cpp:52
double OSiRand(int iMin, int iMax)
OSiRand(int iMin, int iMax)
Definition: OSMathUtil.cpp:279
a sparse matrix data structure
Definition: OSGeneral.h:223
void fint fint * k
int getMult(int *i, int size)
getMult
Definition: OSMathUtil.h:246
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
Definition: OSMathUtil.h:168
this class has routines for linear algebra.
Definition: OSMathUtil.h:57
MathUtil()
the class constructor
Definition: OSMathUtil.cpp:48
static Bigint * mult(Bigint *a, Bigint *b)
Definition: OSdtoa.cpp:857
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
std::string format_os_dtoa(double x)
void fint fint fint real fint real * x