1 /*! ========================================================================
2 ** Extended Template and Library
4 ** $Id: _misc.h,v 1.1.1.1 2005/01/04 01:31:47 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __ETL__MISC_H_
25 #define __ETL__MISC_H_
27 /* === H E A D E R S ======================================================= */
32 /* === M A C R O S ========================================================= */
34 /* === T Y P E D E F S ===================================================== */
36 /* === C L A S S E S & S T R U C T S ======================================= */
40 template<typename I, typename T> inline I
41 binary_find(I begin, I end, const T& value)
44 I iter(begin+(end-begin)/2);
46 while(end-begin>1 && !(*iter==value))
48 ((*iter<value)?begin:end) = iter;
50 iter = begin+(end-begin)/2;
54 size_t len_(end-begin);
60 while(len_>1 && !(*iter==value))
62 ((*iter<value)?begin:end) = iter;
74 /*! \fixme Isn't there some x86 FPU instruction for quickly
75 ** converting a float to a rounded integer? It's worth
76 ** looking into at some point... */
77 inline int round_to_int(const float x) { return static_cast<int>(x+0.5f); }
78 inline int round_to_int(const double x) { return static_cast<int>(x+0.5); }
80 inline int ceil_to_int(const float x) { return static_cast<int>(ceil(x)); }
81 inline int ceil_to_int(const double x) { return static_cast<int>(ceil(x)); }
83 inline int floor_to_int(const float x) { return static_cast<int>(x); }
84 inline int floor_to_int(const double x) { return static_cast<int>(x); }
88 /* === E X T E R N S ======================================================= */
90 /* === E N D =============================================================== */