/usr/include/BALL/MATHS/common.h is in libball1.4-dev 1.4.1+20111206-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: common.h,v 1.29.16.1 2007/03/25 21:23:45 oliver Exp $
//
#ifndef BALL_MATHS_COMMON_H
#define BALL_MATHS_COMMON_H
#ifndef BALL_CONFIG_CONFIG_H
# include <BALL/CONFIG/config.h>
#endif
#include <math.h>
#ifdef BALL_HAS_IEEEFP_H
# include <ieeefp.h>
#endif
#ifdef BALL_HAS_FLOAT_H
# include <float.h>
#endif
#ifndef BALL_COMMON_CONSTANTS_H
# include <BALL/COMMON/constants.h>
#endif
#ifndef BALL_COMMON_GLOBAL_H
# include <BALL/COMMON/global.h>
#endif
#ifndef BALL_COMMON_MACROS_H
# include <BALL/COMMON/macros.h>
#endif
namespace BALL
{
namespace Maths
{
/** \defgroup MathsCommon Common Mathematical Functions
<b>Namespace:</b> <tt>BALL::Maths</tt> \par
*/
//@{
/** Return the absolute value of a number.
@param t the number
@return T the absolute value
*/
template <typename T>
inline
T abs(const T& t)
{
return BALL_ABS(t);
}
/** Return the fraction of a number.
@param t the number
@return T the fraction
*/
template <typename T>
inline
T frac(const T& t)
{
long tmp = (long)t;
return (t - (T)tmp);
}
#ifndef max
/** Return the greater of two numbers.
@param a the first number
@param b the second number
@return T the greatest number
*/
template <typename T>
inline
T max(const T& a, const T& b)
{
return BALL_MAX(a, b);
}
/** Return the greatest of three numbers.
@param a the first number
@param b the second number
@param ct the third number
@return T the greatest number
*/
template <typename T>
inline
T max(const T& a, const T& b, const T &ct)
{
return BALL_MAX3(a, b, ct);
}
#endif
#ifndef min
/** Return the smallest of two numbers.
@param a the first number
@param b the second number
@return T the smallest number
*/
template <typename T>
inline
T min(const T& a, const T& b)
{
return BALL_MIN(a, b);
}
/** Return the smallest of three numbers.
@param a the first number
@param b the second number
@param ct the third number
@return T the smallest number
*/
template <typename T>
inline
T min(const T& a, const T& b, const T &ct)
{
return BALL_MIN3(a, b, ct);
}
#endif
/** Round a number and return the result.
@param t the number
@return T the result
*/
template <typename T>
inline
T round(const T& t)
{
return (T)(t > 0 ? long(t + 0.5) : long(t - 0.5));
}
/** Return the sign of a number.
@param t the number
@return Index <tt>-1</tt> t < 0; <tt>0</tt> t = 0; <tt>1</tt> t > 0
*/
template <typename T>
inline
T sgn(const T& t)
{
return BALL_SGN(t);
}
/** Test whether a number is finite.
@param t the number
@return bool, <b>true</b> if <tt>t</tt> is finite
*/
template <typename T>
inline
bool isFinite(const T& t)
{
#ifdef BALL_COMPILER_MSVC
return ::_finite(t);
#else
return finite(t);
#endif
}
/** Test whether a value is not a number.
@param t the number
@return bool, <b>true</b> if t equals <tt>nan</tt>
*/
template <typename T>
inline
bool isNan(const T& t)
{
#ifdef BALL_COMPILER_MSVC
return (_isnan(t) != 0);
#elif defined(BALL_OS_DARWIN)
return ( __inline_isnand(t) != 0);
#else
return (isnan(t) != 0);
#endif
}
/** Test whether a number is infinite.
@param t the number
@return bool, <b>true</b> if <tt>t</tt> equals <tt>inf</tt> or <tt>-inf</tt>
*/
template <typename T>
inline
bool isInfinite(const T& t)
{
return (!Maths::isFinite(t) && !Maths::isNan(t));
}
/** Test whether a number is zero.
@param t the number
@return bool, <b>true</b> if the absolute value of <tt>t</tt> is below \link Constants::EPSILON Constants::EPSILON \endlink
*/
template <typename T>
inline
bool isZero(const T& t)
{
return (abs(t) < Constants::EPSILON);
}
/** Test whether a number is not zero.
@param t the number
@return bool, <b>true</b>, if the absolute value of <tt>t</tt> is at least \link Constants::EPSILON Constants::EPSILON \endlink
*/
template <typename T>
inline
bool isNotZero(const T& t)
{
return (abs(t) >= Constants::EPSILON);
}
/** Test whether a number is equal to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if the absolute distance of <tt>a</tt> and <tt>b</tt> is below \link Constants::EPSILON Constants::EPSILON \endlink
*/
template <typename T1, typename T2>
inline
bool isEqual(const T1& a, const T2& b)
{
return (abs(a - b) < Constants::EPSILON);
}
/** Test whether a number is not equal to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if the absolute distance of <tt>a</tt> and <tt>b</tt> is at least \link Constants::EPSILON Constants::EPSILON \endlink
*/
template <typename T1, typename T2>
inline
bool isNotEqual(const T1& a, const T2& b)
{
return (abs(a - b) >= Constants::EPSILON);
}
/** Test whether a number is less compared to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if <tt>a</tt> is smaller than <tt>b</tt>
*/
template <typename T1, typename T2>
inline
bool isLess(const T1& a, const T2& b)
{
return ((a - b) <= -Constants::EPSILON);
}
/** Test whether a number is less or equal compared to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if <tt>a</tt> is less or equal <tt>b</tt>
*/
template <typename T1, typename T2>
inline
bool isLessOrEqual(const T1& a, const T2& b)
{
return ((a - b) < Constants::EPSILON);
}
/** Test whether a number is greater or equal compared to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if <tt>a</tt> is greater or equal than <tt>b</tt>
*/
template <typename T1, typename T2>
inline
bool isGreaterOrEqual(const T1& a, const T2& b)
{
return ((a - b) > -Constants::EPSILON);
}
/** Test whether a number is greater compared to another.
@param a the first number
@param b the second number
@return bool, <b>true</b> if <tt>a</tt> is greater than <tt>b</tt>
*/
template <typename T1, typename T2>
inline
bool isGreater(const T1& a, const T2& b)
{
return (a - b >= Constants::EPSILON);
}
/** Return the floor of a number.
@param t the number
@return T the floor
*/
template <typename T>
inline
long floor(const T& t)
{
return (long)(Maths::isGreater(t, 0) ? t: (Maths::isEqual(t, (T)(long)t) ? t : t - 1));
}
/** Return the ceiling of a number.
@param t the number
@return T the ceiling
*/
template <typename T>
inline
long ceiling(const T& t)
{
return (long)(Maths::isLess(t, 0) ? t: (Maths::isEqual(t, (T)(long)t) ? t : t + 1));
}
/** Compare two numbers to each other.
@param a the first number
@param b the second number
@return Index <tt>-1</tt> a < b; <tt>0</tt> a = b; <tt>1</tt> a > b
*/
template <typename T1, typename T2>
inline
Index compare(const T1& a, const T2& b)
{
return (Maths::isLess(a, b) ? -1 : Maths::isEqual(a, b) ? 0 : 1);
}
/** Test whether two numbers are close to each other.
@param a the first number
@param b the second number
@param max_diff the maximum allowed difference between the two numbers
@return bool, <b>true</b> if the absolute distance between <tt>a</tt> and <tt>b</tt> is below <tt>max_diff</tt>
*/
template <typename T>
inline
bool isNear(const T& a, const T& b, const T& max_diff)
{
return (abs((double)a - (double)b) < abs((double)max_diff));
}
/// round to integral value in floating-point format
inline double rint(double x)
{
if (x < 0.0) return (double)(int)(x - 0.5);
else return (double)(int)(x + 0.5);
}
//@}
} // namespace Maths
} // namespace BALL
#endif // BALL_MATHS_COMMON_H
|