My Project
OSMathUtil.h
Go to the documentation of this file.
1/* $Id$ */
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
32extern std::string os_dtoa_format(double x);
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39 double os_strtod_wrap(const char *str, char **strEnd);
40
41#ifdef __cplusplus
42}
43#endif
44
58{
59public:
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);
137
146 //double os_strtod_wrap(const char *str, const char *strEnd);
147
148
149
150};//class MathUtil
151
152
168inline 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
206inline 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
246inline 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
274inline 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
298double OSRand();
299
300
308double OSiRand(int iMin, int iMax);
309
310#endif
std::string os_dtoa_format(double x)
double OSiRand(int iMin, int iMax)
OSiRand(int iMin, int iMax)
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
Definition OSMathUtil.h:168
int getMult(int *i, int size)
getMult
Definition OSMathUtil.h:246
double OSRand()
OSRand()
double os_strtod_wrap(const char *str, char **strEnd)
static Bigint * mult(Bigint *a, Bigint *b)
Definition OSdtoa.cpp:857
this class has routines for linear algebra.
Definition OSMathUtil.h:58
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.
MathUtil()
the class constructor
~MathUtil()
the class destructor
std::string format_os_dtoa(double x)
a sparse matrix data structure
Definition OSGeneral.h:224