util.h
00001 /*
00002  * util.h
00003  *
00004  *  Created on: Sep 1, 2008
00005  *      Author: tdillig
00006  */
00007 
00008 #ifndef UTIL_H_
00009 #define UTIL_H_
00010 
00011 #include <string>
00012 #include <vector>
00013 #include <stdlib.h>
00014 using namespace std;
00015 
00016 //#define DWORD_ALIGN(x) ((((x)+3)/4)*4)
00017 
00018 string int_to_string(long l);
00019 long int string_to_int(string s);
00020 static inline void  address_to_string(string & res, void* v)
00021 {
00022         char temp[100];
00023         temp[0] = 'a';
00024         sprintf(temp+1, "%lu", (unsigned long int) v);
00025         res.append(temp);
00026 }
00027 string float_to_string(float f);
00028 string linear_system_to_string(int* matrix, int num_rows, int num_cols,
00029                 vector<string>& vars);
00030 inline bool have_same_sign(long int a, long int b)
00031 {
00032         long int temp = a ^ b;
00033         return !(temp & (1L << 63));
00034 
00035 }
00036 
00037 
00038 inline long int gcd(long int _a, long int _b)
00039 {
00040         long int a = labs(_a);
00041         long int b = labs(_b);
00042 
00043         int t;
00044         while(b!=0){
00045                 t = a;
00046                 a = b;
00047                 b = t % b;
00048         }
00049         return a;
00050 }
00051 
00052 inline long int lcm(long int a, long int b)
00053 {
00054         long int d = gcd(a, b);
00055         return labs(a*b/d);
00056 }
00057 
00058 
00059 
00060 #endif /* UTIL_H_ */