ct_common
1.0.1
Common library for combinatorial testing
|
00001 //===----- ct_common/common/arithmetic_utils.h ------------------*- C++ -*-===// 00002 // 00003 // The ct_common Library 00004 // 00005 // This file is distributed under the MIT license. See LICENSE for details. 00006 // 00007 //===----------------------------------------------------------------------===// 00008 // 00009 // This header file contains some basic arithmetic utility functions 00010 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #ifndef CT_COMMON_ARITHMETIC_UTILS_H_ 00014 #define CT_COMMON_ARITHMETIC_UTILS_H_ 00015 00016 #include <cmath> 00017 #include <vector> 00018 #include <algorithm> 00019 00020 namespace ct { 00021 namespace common { 00022 namespace utils{ 00023 00024 inline bool cmp_eq(int a, int b) { 00025 return a == b; 00026 } 00027 00028 inline bool cmp_ge(int a, int b) { 00029 return a >= b; 00030 } 00031 00032 inline bool cmp_gt(int a, int b) { 00033 return a > b; 00034 } 00035 00036 inline bool cmp_le(int a, int b) { 00037 return a <= b; 00038 } 00039 00040 inline bool cmp_lt(int a, int b) { 00041 return a < b; 00042 } 00043 00044 inline bool cmp_ne(int a, int b) { 00045 return a != b; 00046 } 00047 00048 inline bool cmp_eq(double a, double b, double prec = 0) { 00049 return fabs(a - b) <= prec; 00050 } 00051 00052 inline bool cmp_ge(double a, double b, double prec = 0) { 00053 return (a - b) >= -prec; 00054 } 00055 00056 inline bool cmp_gt(double a, double b, double prec = 0) { 00057 return (a - b) > prec; 00058 } 00059 00060 inline bool cmp_le(double a, double b, double prec = 0) { 00061 return (a - b) <= prec; 00062 } 00063 00064 inline bool cmp_lt(double a, double b, double prec = 0) { 00065 return (a - b) < -prec; 00066 } 00067 00068 inline bool cmp_ne(double a, double b, double prec = 0) { 00069 return fabs(a - b) > prec; 00070 } 00071 00072 inline std::vector<std::size_t> sort_and_uniquefy(const std::vector<std::size_t> &vec) { 00073 std::vector<std::size_t> tmp_return = vec; 00074 std::sort(tmp_return.begin(), tmp_return.end()); 00075 tmp_return.erase(std::unique(tmp_return.begin(), tmp_return.end()), tmp_return.end()); 00076 return tmp_return; 00077 } 00078 00079 } // namespace utils 00080 } // namespace common 00081 } // namespace ct 00082 00083 #endif // CT_COMMON_ARITHMETIC_UTILS_H_