OS  2.9.3
OSMathUtil.h
Go to the documentation of this file.
1 /* $Id: OSMathUtil.h 4985 2015-03-12 14:14:49Z tkr $ */
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  */
114  bool isColumnMajor, int startSize, int valueSize, int* start, int* index,
115  double* value, int dimension);
116 
122  std::string format_os_dtoa( double x);
123 
124 
133  //double os_strtod_wrap(const char *str) throw(ErrorClass);
134 
143  //double os_strtod_wrap(const char *str, const char *strEnd) throw(ErrorClass);
144 
145 
146 
147 };//class MathUtil
148 
149 
165 inline void getMultIncr(int* i, int *mult, int *incr, int size, int defaultIncr)
166 {
167  int k;
168 
169  *mult = 1;
170  *incr = defaultIncr;
171 
172  if (size == 1) return;
173 
174  for (k=1; (k < size) && (i[k] - i[k-1] == defaultIncr); k++)
175  {
176  (*mult)++;
177  }
178  if (*mult > 1 || size == 2) return;
179 
180  *incr = i[1] - i[0];
181  if (i[2] - i[1] != *incr) return;
182 
183  *mult = 3;
184  for (k=3; (k < size) && (i[k] - i[k-1] == *incr); k++)
185  {
186  (*mult)++;
187  }
188  return;
189 }
190 
191 
203 inline void getMultIncr(double* a, int *mult, double *incr, int size)
204 {
205  double mark;
206  int k;
207 
208  *mult = 1;
209  *incr = 0;
210 
211  if (size == 1) return;
212 
213  mark = a[0];
214  for (k=1; (k < size) && (a[k] == mark); k++)
215  {
216  (*mult)++;
217  }
218  if (*mult > 1 || size == 2) return;
219 
220  *incr = a[1] - a[0];
221  if (a[2] - a[1] != *incr) return;
222 
223  *mult = 3;
224  for (k=3; (k < size) && (a[k] - a[k-1] == *incr); k++)
225  {
226  (*mult)++;
227  }
228  return;
229 }
230 
231 
232 
243 inline int getMult(int* i, int size)
244 {
245  int mark;
246 
247  int mult = 1;
248 
249  if (size == 1) return mult;
250 
251  mark = i[0];
252  for (int k=1; (k < size) && (i[k] == mark); k++)
253  {
254  mult++;
255  }
256  return mult;
257 }
258 
259 
260 
271 inline int getMult(double* a, int size)
272 {
273  double mark;
274 
275  int mult = 1;
276 
277  if (size == 1) return mult;
278 
279  mark = a[0];
280  for (int k=1; (k < size) && (a[k] == mark); k++)
281  {
282  mult++;
283  }
284  return mult;
285 }
286 
287 
295 double OSRand();
296 
297 
305 double OSiRand(int iMin, int iMax);
306 
307 
308 #endif
int getMult(int *i, int size)
getMult
Definition: OSMathUtil.h:243
double OSRand()
OSRand()
~MathUtil()
the class destructor
std::string format_os_dtoa(double x)
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.
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
Definition: OSMathUtil.h:165
a sparse matrix data structure
Definition: OSGeneral.h:223
MathUtil()
the class constructor
double os_strtod_wrap(const char *str, char **strEnd)
this class has routines for linear algebra.
Definition: OSMathUtil.h:57
double OSiRand(int iMin, int iMax)
OSiRand(int iMin, int iMax)