Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

defs.hpp

Go to the documentation of this file.
00001 /* --------------------------------------------------------------- *\
00002 
00003    author:
00004 
00005       mathias gumz
00006 
00007 \* --------------------------------------------------------------- */
00008 
00009 #ifndef _DEFS_HPP_
00010 #define _DEFS_HPP_
00011 
00012 
00013 #include <ak/platform.hpp>
00014 
00015 
00016 namespace math
00017 {
00018 
00019 #ifndef M_PI
00020 # define M_PI       3.14159265358979323846
00021 # define M_PI_2     1.57079632679489661923
00022 # define M_PI_4     0.78539816339744830962
00023 # define M_1_PI     0.31830988618379067154
00024 # define M_2_PI     0.63661977236758134308
00025 # define M_2_SQRTPI 1.12837916709551257390
00026 #endif // M_PI
00027 
00028 #ifndef atan2
00029 double atan2(double y, double x)
00030 {
00031   float dvp, dvn;
00032   if(x > 0.0)
00033   {
00034     dvp= 1.0;
00035     dvn= 0.0;
00036   } else
00037   {
00038     dvp= 0.0;
00039     dvn= 1.0;
00040   }
00041 
00042   float dhn = (y < 0) ? 1.0 : 0.0;
00043   float psi;
00044   if (y == 0.0)
00045     psi= M_PI_2 * (dvp + 3.0 * dvn);
00046   else if (x == 0.0)
00047     psi= M_PI * dhn;
00048   else
00049     psi= atan(x/y) + M_PI * dhn * dvp
00050        + (M_PI + M_PI * (y > 0.0)) * dvn;
00051   return psi * (180.0*M_1_PI);
00052 }
00053 #endif // atan2
00054 
00055 
00056 
00057 /* --------------------------------------------------------------- *\
00058     some nifty tools from modernc++design.com
00059 \* --------------------------------------------------------------- */
00060 
00061 template<int> struct CompileTimeError;
00062 template<> struct CompileTimeError<true> {};
00063 #define STATIC_CHECK(expr, msg) \
00064     { CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }
00065 
00066 
00067 template <int v>
00068 struct Int2Type
00069 {
00070   enum { value= v };
00071 }; // struct Int2Type
00072 
00073 
00074 template<typename T>
00075 struct Traits
00076 {
00077   T static zero() { return T(0); };
00078   T static one()  { return T(1); };
00079   T static inv()  { return T(-1); };
00080 };
00081 
00082 
00083 
00084 template<class T, int S>
00085 struct Chunk
00086 {
00087   T*        begin()       { return &val[0]; };
00088   const T*  begin() const { return &val[0]; };
00089   T*        end()         { return &val[S]; };
00090   const T*  end()   const { return &val[S]; };
00091 
00092   const T&  operator[](const unsigned int i) const { return val[i]; };
00093   T&        operator[](const unsigned int i)       { return val[i]; };
00094 
00095   static unsigned int size() { return S; };
00096   static unsigned int bytesize() { return sizeof(Chunk<T, S>); }
00097 
00098   mutable T val[S];
00099 }; //  struct Chunk
00100 
00101 #include <ak/defs.inl>
00102 
00103 }; // namespace math
00104 
00105 #endif // _DEFS_HPP_
00106 

Generated on Tue Sep 2 11:33:27 2003 for math by doxygen 1.3.2