00001
00022
00023
00024 #ifndef __ETL__MISC_H_
00025 #define __ETL__MISC_H_
00026
00027
00028 #include <cmath>
00029
00030 #include <math.h>
00031
00032
00033
00034
00035
00036
00037
00038 _ETL_BEGIN_NAMESPACE
00039
00040 template<typename I, typename T> inline I
00041 binary_find(I begin, I end, const T& value)
00042 {
00043 #if 1
00044 I iter(begin+(end-begin)/2);
00045
00046 while(end-begin>1 && !(*iter==value))
00047 {
00048 ((*iter<value)?begin:end) = iter;
00049
00050 iter = begin+(end-begin)/2;
00051 }
00052 return iter;
00053 #else
00054 size_t len_(end-begin);
00055 size_t half_(len_/2);
00056
00057 I iter(begin);
00058 iter+=half_;
00059
00060 while(len_>1 && !(*iter==value))
00061 {
00062 ((*iter<value)?begin:end) = iter;
00063
00064 len_=half_;
00065 half_/=2;
00066
00067 iter=begin;
00068 iter+=half_;
00069 }
00070 return iter;
00071 #endif
00072 }
00073
00077 inline int round_to_int(const float x) { return static_cast<int>(x+0.5f); }
00078 inline int round_to_int(const double x) { return static_cast<int>(x+0.5); }
00079
00080 inline int ceil_to_int(const float x) { return static_cast<int>(ceil(x)); }
00081 inline int ceil_to_int(const double x) { return static_cast<int>(ceil(x)); }
00082
00083 inline int floor_to_int(const float x) { return static_cast<int>(x); }
00084 inline int floor_to_int(const double x) { return static_cast<int>(x); }
00085
00086 _ETL_END_NAMESPACE
00087
00088
00089
00090
00091
00092 #endif