1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/****************************************************************************
* Core Library Version 1.7, August 2004
* Copyright (c) 1995-2004 Exact Computation Project
* All rights reserved.
*
* This file is part of CORE (http://cs.nyu.edu/exact/core/); you may
* redistribute it under the terms of the Q Public License version 1.0.
* See the file LICENSE.QPL distributed with CORE.
*
* Licensees holding a valid commercial license may use this file in
* accordance with the commercial license agreement provided with the
* software.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*
* File: CoreAux.h
* Synopsis:
* Auxilliary functions
*
* Written by
* Chee Yap <yap@cs.nyu.edu>
* Chen Li <chenli@cs.nyu.edu>
* Zilin Du <zilin@cs.nyu.edu>
*
* WWW URL: http://cs.nyu.edu/exact/
* Email: exact@cs.nyu.edu
*
* $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.2-branch/Core/include/CORE/CoreAux.h $
* $Id: CoreAux.h 28685 2006-02-22 15:22:27Z glisse $
***************************************************************************/
#ifndef _CORE_COREAUX_H_
#define _CORE_COREAUX_H_
#include <iostream>
#include <fstream>
#include "CORE/Impl.h"
CORE_BEGIN_NAMESPACE
#ifndef LONG_BIT // such as in Linux
#define LONG_BIT (sizeof(long) * 8)
#endif
/// CORE_EPS is unit roundoff for IEEE standard double, i.e., 2^{-53}.
// NOTES:
// (1) CORE_EPS is used in our Floating Point Filter (Filter.h)
// (2) 2^{-53} is called "unit roundoff" and
// is the roundoff error for numbers in the range [1,2).
// "Machine epsilon" is 2*CORE_EPS = 2^{-52}. It is the
// smallest gap between two normal machine numbers --Chee 8/2003
//
// const double eps = (ldexp(1.0, -53)); // fails to link on SunPro
#define CORE_EPS ((1.0/(1<<30))/(1<<23))
//
#define CORE_MACHINE_EPS ((1.0/(1<<30))/(1<<22))
/// relEps is relative error for IEEE standard double, 1+2^{-52}.
const double relEps = (1.0 + std::ldexp(1.0, -52));
/// CORE_DIAGFILE is used for all warning and error messages
extern char* CORE_DIAGFILE;
/// template function returns the maximum value of two
template <class T>
inline const T& core_max(const T& a, const T& b) {
return ((a > b) ? a : b);
}
/// template function returns the minimum value of two
template <class T>
inline const T& core_min(const T& a, const T& b) {
return ((a < b) ? a : b);
}
/// template function returns the maximum value of three
template <class T>
inline const T& core_max(const T& a, const T& b, const T& c) {
return ((a > b) ? core_max(a, c) : core_max(b, c));
}
/// template function swaps two values
template <class T>
inline void core_swap(T& a, T& b) {
T tmp;
tmp = a;
a = b;
b = tmp;
}
/// template function rotate three values
template <class T>
inline void core_rotate(T& a, T& b, T& c) {
T tmp;
tmp = a;
a = b;
b = c;
c = tmp;
}
/// template function returns the minimum value of three
template <class T>
inline const T& core_min(const T& a, const T& b, const T& c) {
return ((a < b) ? core_min(a, c) : core_min(b, c));
}
/// template function returns the absolute value
template <class T>
inline const T core_abs(const T& a) {
return ((a < T(0)) ? -a : a);
}
/// returns floor log base 2 of abs(x)
/** CONVENTION: lg(0) = -1 */
int flrLg(long x);
/// returns floor log base 2 of unsigned long x
/** CONVENTION: lg(0) = -1 */
int flrLg(unsigned long x);
/// returns ceiling log base 2 of abs(x)
/** CONVENTION: lg(0) = -1 */
int clLg(long x);
/// returns ceiling log base 2 of unsigned long x
/** CONVENTION: lg(0) = -1 */
int clLg(unsigned long x);
/// gcd for machine type long
long gcd(long m, long n);
/// abs for int type
inline int abs(int x) {
return (x>=0) ? x : (-x);
}
/// abs for long type
inline long abs(long x) {
return (x>=0) ? x : (-x);
}
/// sign for int type
inline int sign(int x) {
return (x==0) ? 0 : ((x>0) ? 1 : (-1));
}
/// sign for long type
inline long sign(long x) {
return (x==0) ? 0 : ((x>0) ? 1 : (-1));
}
/// overloaded << to print out std::string
inline std::ostream& operator<< (std::ostream& o, const std::string& s) {
o << s.c_str();
return o;
}
/// implements the "integer mantissa" function
// (See CORE_PATH/progs/ieee/frexp.cpp for details)
double IntMantissa(double d);
/// implements the "integer exponent" function
// (See CORE_PATH/progs/ieee/frexp.cpp for details)
int IntExponent(double d);
/// Writes out an error or warning message in the local file CORE_DIAGFILE
/** If last argument (err) is TRUE, then this is considered an error
* (not just warning). In this case, the message is also printed in
* std::cerr, using std::perror().
* */
void core_error(std::string msg, std::string file, int lineno, bool err);
/// This is for debugging messages
inline void core_debug(std::string msg){
std::cout << __FILE__ << "::" << __LINE__ << ": " << msg
<< std::endl;
}
CORE_END_NAMESPACE
#endif // _CORE_COREAUX_H_
|