BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/CORE/CoreAux.h
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Core Library Version 1.7, August 2004
00003  * Copyright (c) 1995-2004 Exact Computation Project
00004  * All rights reserved.
00005  *
00006  * This file is part of CORE (http://cs.nyu.edu/exact/core/); you may
00007  * redistribute it under the terms of the Q Public License version 1.0.
00008  * See the file LICENSE.QPL distributed with CORE.
00009  *
00010  * Licensees holding a valid commercial license may use this file in
00011  * accordance with the commercial license agreement provided with the
00012  * software.
00013  *
00014  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00015  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00016  *
00017  *
00018  * File: CoreAux.h
00019  * Synopsis:
00020  *      Auxilliary functions
00021  *
00022  * Written by 
00023  *       Chee Yap <yap@cs.nyu.edu>
00024  *       Chen Li <chenli@cs.nyu.edu>
00025  *       Zilin Du <zilin@cs.nyu.edu>
00026  *
00027  * WWW URL: http://cs.nyu.edu/exact/
00028  * Email: exact@cs.nyu.edu
00029  *
00030  * $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Core/include/CGAL/CORE/CoreAux.h $
00031  * $Id: CoreAux.h 37060 2007-03-13 18:10:39Z reichel $
00032  ***************************************************************************/
00033 
00034 #ifndef _CORE_COREAUX_H_
00035 #define _CORE_COREAUX_H_
00036 
00037 #include <iostream>
00038 #include <fstream>
00039 #include "CGAL/CORE/Impl.h"
00040 
00041 CORE_BEGIN_NAMESPACE
00042 
00043 #ifndef LONG_BIT // such as in Linux
00044   #define LONG_BIT (sizeof(long) * 8)
00045 #endif
00046 
00048 // NOTES:
00049 // (1) CORE_EPS is used in our Floating Point Filter (Filter.h)
00050 // (2) 2^{-53} is called "unit roundoff" and
00051 //      is the roundoff error for numbers in the range [1,2).
00052 //      "Machine epsilon" is 2*CORE_EPS = 2^{-52}.  It is the
00053 //      smallest gap between two normal machine numbers  --Chee 8/2003
00054 //
00055 // const double eps = (ldexp(1.0, -53)); // fails to link on SunPro
00056 #define CORE_EPS ((1.0/(1<<30))/(1<<23))
00057 // 
00058 #define CORE_MACHINE_EPS ((1.0/(1<<30))/(1<<22))
00059 
00061 const double relEps = (1.0 + std::ldexp(1.0, -52));
00062 
00064 extern const char* CORE_DIAGFILE;
00065 
00067 template <class T>
00068 inline const T& core_max(const T& a, const T& b) {
00069   return ((a > b) ? a : b);
00070 }
00071 
00073 template <class T>
00074 inline const T& core_min(const T& a, const T& b) {
00075   return ((a < b) ? a : b);
00076 }
00077 
00079 template <class T>
00080 inline const T& core_max(const T& a, const T& b, const T& c) {
00081   return ((a > b) ? core_max(a, c) : core_max(b, c));
00082 }
00083 
00085 template <class T>
00086 inline  void core_swap(T& a, T& b) {
00087   T tmp;
00088   tmp = a;
00089   a = b;
00090   b = tmp;
00091 }
00092 
00094 template <class T>
00095 inline  void core_rotate(T& a, T& b, T& c) {
00096   T tmp;
00097   tmp = a;
00098   a = b;
00099   b = c;
00100   c = tmp;
00101 }
00102 
00104 template <class T>
00105 inline const T& core_min(const T& a, const T& b, const T& c) {
00106   return ((a < b) ? core_min(a, c) : core_min(b, c));
00107 }
00108 
00110 template <class T>
00111 inline const T core_abs(const T& a) {
00112   return ((a < T(0)) ? -a : a);
00113 }
00114 
00116 
00117 int flrLg(long x);
00118 
00120 
00121 int flrLg(unsigned long x);
00122 
00124 
00125 int clLg(long x);
00126 
00128 
00129 int clLg(unsigned long x);
00130 
00132 long gcd(long m, long n);
00133 
00135 inline int abs(int x) {
00136   return (x>=0) ? x : (-x);
00137 }
00138 
00140 inline long abs(long x) {
00141   return (x>=0) ? x : (-x);
00142 }
00143 
00145 inline int sign(int x) {
00146   return (x==0) ? 0 : ((x>0) ? 1 : (-1));
00147 }
00148 
00150 inline long sign(long x) {
00151   return (x==0) ? 0 : ((x>0) ? 1 : (-1));
00152 }
00153 
00155 inline std::ostream& operator<< (std::ostream& o, const std::string& s) {
00156   o << s.c_str();
00157   return o;
00158 }
00159 
00161 //      (See CORE_PATH/progs/ieee/frexp.cpp for details)
00162 double IntMantissa(double d);
00163 
00165 //      (See CORE_PATH/progs/ieee/frexp.cpp for details)
00166 int IntExponent(double d);
00167 
00169 
00173 void core_error(std::string msg, std::string file, int lineno, bool err);
00175 inline void core_debug(std::string msg){
00176   std::cout << __FILE__ << "::" << __LINE__ << ": " << msg
00177             << std::endl;
00178 }
00179 
00180 
00181 CORE_END_NAMESPACE
00182 #endif // _CORE_COREAUX_H_
00183 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines