_misc.h

Go to the documentation of this file.
00001 
00022 /* === S T A R T =========================================================== */
00023 
00024 #ifndef __ETL__MISC_H_
00025 #define __ETL__MISC_H_
00026 
00027 /* === H E A D E R S ======================================================= */
00028 #include <cmath>
00029 
00030 #include <math.h>
00031 
00032 /* === M A C R O S ========================================================= */
00033 
00034 /* === T Y P E D E F S ===================================================== */
00035 
00036 /* === C L A S S E S & S T R U C T S ======================================= */
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 
00074 inline int round_to_int(const float x) {
00078     return static_cast<int>(x+0.5f);
00079 }
00080 inline int round_to_int(const double x) { return static_cast<int>(x+0.5); }
00081 
00082 inline int ceil_to_int(const float x) { return static_cast<int>(ceil(x)); }
00083 inline int ceil_to_int(const double x) { return static_cast<int>(ceil(x)); }
00084 
00085 inline int floor_to_int(const float x) { return static_cast<int>(x); }
00086 inline int floor_to_int(const double x) { return static_cast<int>(x); }
00087 
00088 _ETL_END_NAMESPACE
00089 
00090 /* === E X T E R N S ======================================================= */
00091 
00092 /* === E N D =============================================================== */
00093 
00094 #endif

Generated on Sat Oct 27 11:30:17 2007 for ETL by  doxygen 1.5.3-20071008