/home/coin/SVN-release/OS-2.3.4/OS/src/OSUtils/OSMathUtil.h

Go to the documentation of this file.
00001 /* $Id: OSMathUtil.h 3821 2010-11-04 17:30:32Z Gassmann $ */
00022 #ifndef MATHUTIL_H
00023 #define MATHUTIL_H
00024  
00025 #include "OSParameters.h"
00026 #include "OSdtoa.h"
00027 #include "OSErrorClass.h"
00028 #include "OSGeneral.h"
00029 
00030 
00031 #include <sstream>  
00032 #include<string>
00033 
00034 
00035 #ifdef __cplusplus
00036 extern "C" std::string os_dtoa_format(double  x);
00037 extern "C" double os_strtod_wrap(const char *str,   char **strEnd);
00038 #else
00039 #ifdef __STDC__
00040 std::string os_dtoa_format(double  x);
00041 double os_strtod_wrap(const char *str,  char **strEnd);
00042 #endif
00043 #endif 
00044 
00045 
00046 using std::ostringstream; 
00047 
00060 class MathUtil{
00061         public:
00062 
00064         MathUtil();
00065         
00067         ~MathUtil();
00068         
00076         /*public static double round (double x, int precision){
00077                 double mask = 0.0, y, result;           
00078                 try{
00079                         mask = Math.pow (10.0, -(double)precision);
00080                 }
00081                 catch(ArithmeticException e){
00082                         return x;
00083                 }
00084                 y  = mod(x, mask);
00085                 result  = x - y;
00086                 if (y / mask >= 0.5) result += mask;
00087                 return result;
00088         }//round
00089         */
00097         /*public static double mod (double x, double y){
00098                 return  x - Math.floor(x / y) * y;
00099         }//mod
00100         */
00115         static SparseMatrix* convertLinearConstraintCoefficientMatrixToTheOtherMajor(
00116                         bool isColumnMajor, int startSize, int valueSize, int* start, int* index, 
00117                         double* value, int dimension);
00118         
00124         std::string format_os_dtoa( double x);
00125         
00126         
00135         //double os_strtod_wrap(const char *str) throw(ErrorClass);
00136         
00145         //double os_strtod_wrap(const char *str,  const char *strEnd) throw(ErrorClass);
00146 
00147 
00148 
00149 };//class MathUtil
00150 
00151 
00167 inline void getMultIncr(int* i, int *mult, int *incr, int size, int defaultIncr)
00168 {
00169         int k;
00170 
00171         *mult = 1;
00172         *incr = defaultIncr;
00173 
00174         if (size == 1) return;
00175 
00176         for (k=1; (k < size) && (i[k] - i[k-1] == defaultIncr); k++)
00177         {
00178                 (*mult)++;
00179         }
00180         if (*mult > 1 || size == 2) return;
00181 
00182         *incr = i[1] - i[0];
00183         if (i[2] - i[1] != *incr) return;
00184 
00185         *mult = 3;
00186         for (k=3; (k < size) && (i[k] - i[k-1] == *incr); k++)
00187         {
00188                 (*mult)++;
00189         }
00190         return;
00191 }       
00192 
00193 
00205 inline void getMultIncr(double* a, int *mult, double *incr, int size)
00206 {
00207         double mark;
00208         int k;
00209 
00210         *mult = 1;
00211         *incr = 0;
00212 
00213         if (size == 1) return;
00214 
00215         mark = a[0];
00216         for (k=1; (k < size) && (a[k] == mark); k++)
00217         {
00218                 (*mult)++;
00219         }
00220         if (*mult > 1 || size == 2) return;
00221 
00222         *incr = a[1] - a[0];
00223         if (a[2] - a[1] != *incr) return;
00224 
00225         *mult = 3;
00226         for (k=3; (k < size) && (a[k] - a[k-1] == *incr); k++)
00227         {
00228                 (*mult)++;
00229         }
00230         return;
00231 }       
00232 
00233 
00234 
00245 inline int getMult(int* i, int size)
00246 {
00247         int mark;
00248 
00249         int mult = 1;
00250 
00251         if (size == 1) return mult;
00252 
00253         mark = i[0];
00254         for (int k=1; (k < size) && (i[k] == mark); k++)
00255         {
00256                 mult++;
00257         }
00258         return mult;
00259 }       
00260 
00261 
00262 
00273 inline int getMult(double* a, int size)
00274 {
00275         double mark;
00276 
00277         int mult = 1;
00278 
00279         if (size == 1) return mult;
00280 
00281         mark = a[0];
00282         for (int k=1; (k < size) && (a[k] == mark); k++)
00283         {
00284                 mult++;
00285         }
00286         return mult;
00287 }       
00288 
00289 #endif

Generated on Wed Mar 23 03:06:02 2011 by  doxygen 1.4.7