Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

global.H

Go to the documentation of this file.
00001 #ifndef GLOBAL_H_IS_INCLUDED
00002 #define GLOBAL_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \defgroup group_MLIB MLIB
00006  *  \brief The Jot Math Library.
00007  *
00008  */
00009 
00010 /*!
00011  *  \file global.H
00012  *  \brief The basic include file for mlib; defines constants and
00013  *         inline utility functions.
00014  *  \ingroup group_MLIB
00015  *
00016  */
00017 
00018 // Include some very frequently used header files so that they do not have
00019 // to be included every time
00020 #include <cmath>
00021 #include <cstdio>
00022 #include <cstdlib>
00023 #include <cassert>
00024 
00025 #include "std/support.H"
00026 
00027 /*!
00028  *  \brief Namespace containing all the related code for Jot Math Library (mlib).
00029  *
00030  */
00031 namespace mlib {
00032 
00033 // Some compilers don't define these constants
00034 #if defined(WIN32) || defined(__KCC)
00035 #define M_PI    3.14159265358979323846  //!< \brief pi
00036 #define M_PI_2  1.57079632679489661923  //!< \brief pi/2
00037 #define M_LN2   0.69314718055994530942  //!< \brief ln(2)
00038 #define M_SQRT2 1.41421356237309504880  //!< \brief sqrt(2)
00039 #endif
00040 
00041 #if !defined(TWO_PI)
00042 #define TWO_PI (2*M_PI)                         //!< \brief 2*pi
00043 #endif
00044 
00045 // Convenience -- convert degrees to radians, and vice versa
00046 //! \brief Converts degrees to radians
00047 inline double deg2rad(double degrees) { return degrees * (M_PI/180); }
00048 //! \brief Converts radians to degrees
00049 inline double rad2deg(double radians) { return radians * (180/M_PI); }
00050 
00051 //! \name Epsilon Values
00052 //! Don't use these global variables directly, use the
00053 //! inline functions instead. We have to keep these variables in
00054 //! the header file to be able to inline the access functions.
00055 //@{
00056 
00057 extern double gEpsAbsMath;
00058 extern double gEpsAbsSqrdMath;
00059 extern const double gEpsNorMath;
00060 extern const double gEpsNorSqrdMath;
00061 extern const double gEpsZeroMath;  // Really a very small value
00062 
00063 //@}
00064 
00065 //! \name Epsilon Value Accessor Functions
00066 //! Use these inline functions to access the epsilon value variables rather
00067 //! than accessing the variables directly.
00068 //@{
00069 
00070 inline double epsAbsMath    () { return gEpsAbsMath;     }
00071 inline double epsAbsSqrdMath() { return gEpsAbsSqrdMath; }
00072 
00073 inline double epsNorMath    () { return gEpsNorMath;     }
00074 inline double epsNorSqrdMath() { return gEpsNorSqrdMath; }
00075 
00076 inline double epsZeroMath   () { return gEpsZeroMath;    }
00077 
00078 //! \brief Tell if a double is so small that it is essentially zero:
00079 inline bool isZero(double x)            { return std::fabs(x) < epsZeroMath(); }
00080 //! \brief Tell if two doubles are so close that they are essentially equal:
00081 inline bool isEqual(double x, double y) { return isZero(x-y); }
00082 
00083 //! \brief Set the value of the absolute epsilon constant (and the absolute
00084 //! epsilon squared constant as well). 
00085 extern void setEpsAbsMath(double eps);
00086 
00087 //@}
00088 
00089 //! \name KAI Match Hacks
00090 //! Hack to get around bug in KAI's math functions
00091 //@{
00092 #ifdef __KCC
00093 #define sqrt(x)  std::sqrt(double(x))
00094 #define log(x)   std::log(double(x))
00095 #define pow(x,y) std::pow(double(x),double(y))
00096 #endif
00097 //@}
00098 
00099 //! \brief Safe arc cosine function.
00100 //!
00101 //! Ensures that numerical error doesn't cause a value outside the range [-1,1]
00102 //! to be passed to the acos function by clamping the input value.
00103 inline double Acos(double x)            { return std::acos(clamp(x, -1.0, 1.0)); }
00104 
00105 #if defined(_AIX) || defined(__GNUC__)
00106 #define MLIB_INLINE inline
00107 #else
00108 #define MLIB_INLINE
00109 #endif
00110 
00111 // The following is used to make gdb stop at a specified point
00112 // in a templated function:
00113 void fn_gdb_will_recognize_so_i_can_set_a_fuggin_breakpoint();
00114 
00115 } // namespace mlib
00116 
00117 #endif // GLOBAL_H_IS_INCLUDED

Generated on Mon Sep 18 11:39:30 2006 for jot by  doxygen 1.4.4