00001 //---------------------------------------------------------------------------- 00002 /** @file SgMath.h 00003 Math utility functions. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #ifndef SG_MATH_H 00008 #define SG_MATH_H 00009 00010 #include <cmath> 00011 00012 //---------------------------------------------------------------------------- 00013 00014 /** Square-root of 2. 00015 Can be used instead of M_SQRT2 to support systems that don't define 00016 BSD math constants (Mac OS X Tiger?) 00017 */ 00018 #define SG_SQRT2 1.41421356237309504880 00019 00020 //---------------------------------------------------------------------------- 00021 00022 /** Math utility functions. */ 00023 namespace SgMath 00024 { 00025 /** Round to the closest integer value. */ 00026 int RoundToInt(double v); 00027 } 00028 00029 inline int SgMath::RoundToInt(double v) 00030 { 00031 return static_cast<int>(std::floor(v + 0.5)); 00032 } 00033 //---------------------------------------------------------------------------- 00034 00035 #endif // SG_MATH_H