OBOE
0.1
|
00001 // Copyright (c) 2004-2007 University of Geneva, HEC, Logilab 00002 // 00003 // OBOE is published under the Common Public License. 00004 // 00005 // Authors : 00006 // Nidhi Sawhney <nsawhney@yahoo.com> 00007 // The OBOE team 00008 // 00009 00010 #ifndef ACCPM_DEFS_H 00011 #define ACCPM_DEFS_H 00012 00013 #include <float.h> 00014 #define ACCPM_PLUS_INF DBL_MAX/100 00015 #define ACCPM_MINUS_INF -ACCPM_PLUS_INF 00016 #include <iostream> 00017 #include <cmath> 00018 #include <string.h> 00019 00020 #include <set> 00021 typedef std::set<int> StdIntSet; 00022 00023 inline bool IS_FINITE(double x) { return (x < ACCPM_PLUS_INF && x > ACCPM_MINUS_INF); } 00024 //inline bool DBL_CMP(double x, double y) { return x == y; } 00025 //inline bool DBL_LT(double x, double y) { return (y - x > 0); } 00026 00027 inline bool 00028 DBL_CMP(double A, double B, double precision = 1e-15) 00029 { 00030 if (A == B) 00031 return true; 00032 00033 if (A == 0) { 00034 return std::fabs(B) < 1e-30; 00035 } 00036 if (B == 0) { 00037 return std::fabs(A) < 1e-30; 00038 } 00039 00040 double relativeError; 00041 if (std::fabs(B) > std::fabs(A)) 00042 relativeError = std::fabs((A - B) / B); 00043 else 00044 relativeError = std::fabs((A - B) / A); 00045 if (relativeError <= precision) 00046 return true; 00047 return false; 00048 } 00049 00050 inline bool 00051 DBL_LT(double A, double B, double precision = 1e-14) 00052 { 00053 if (A == B || DBL_CMP(A, B, precision)) 00054 return false; 00055 return A < B; 00056 } 00057 00058 inline bool 00059 DBL_GT(double A, double B, double precision = 1e-14) 00060 { 00061 return (DBL_LT(B, A, precision)); 00062 } 00063 00064 00065 struct ltstr 00066 { 00067 bool operator()(const char* s1, const char* s2) const 00068 { 00069 return strcmp(s1, s2) < 0; 00070 } 00071 }; 00072 00073 inline void AccpmWarning(const char *msg) { std::cout << "WARNING:" << msg << std::endl; } 00074 inline void AccpmError(const char *msg) { std::cout << "ERROR:" << msg << std::endl; } 00075 00076 #endif