Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

math/real.h

Go to the documentation of this file.
00001 #ifndef MATH_REAL_H
00002 #define MATH_REAL_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00033 #include <glt/config.h>
00034 
00035 #include <cfloat>
00036 #include <cmath>
00037 
00038 //
00039 // Basic types, constants
00040 // and functions
00041 //
00042 
00043 // Constants borrowed from PHP
00044 
00045 #define M_PI        3.14159265358979323846
00046 #define M_E         2.7182818284590452354
00047 #define M_LOG2E     1.4426950408889634074
00048 #define M_LOG10E    0.43429448190325182765
00049 #define M_LN2       0.69314718055994530942
00050 #define M_LN10      2.30258509299404568402
00051 #define M_PI_2      1.57079632679489661923
00052 #define M_PI_4      0.78539816339744830962
00053 #define M_1_PI      0.31830988618379067154
00054 #define M_2_PI      0.63661977236758134308
00055 
00056 #ifndef M_SQRTPI
00057 #define M_SQRTPI    1.77245385090551602729
00058 #endif
00059 
00060 #define M_2_SQRTPI  1.12837916709551257390
00061 #define M_SQRT2     1.41421356237309504880
00062 
00063 #ifndef M_SQRT3
00064 #define M_SQRT3     1.73205080756887729352
00065 #endif
00066 
00067 #define M_SQRT1_2   0.70710678118654752440
00068 #define M_LNPI      1.14472988584940017414
00069 #define M_EULER     0.57721566490153286061
00070 
00071 // Other useful constants
00072 
00073 #define M_PI_DEG    (M_PI/180.0)
00074 #define M_DEG_PI    (180.0/M_PI)
00075 #define M_2PI       (2.0*M_PI)
00076 
00078 template <class A>              A SQ(A a) { return a*a; }
00079 
00081 //template <class A, class B>       A SIGN(A a, B b) { return b<0?  -a: a; }
00082 
00083 template <class A> bool SAME_SIGN(A a, A b) { return (a<0 && b<0   ||   a>0 && b>0); }
00084 template <class A> A    CLAMP(const A x, const A min_v, const A max_v) { return x<min_v?  min_v: (x>max_v? max_v: x); }
00085 template <class A> A    LERP(const A &a,const A &b,const double t)     { return a*(1.0-t) + b*t; }
00086 
00087 //template <class A> const A &MIN(const A &a,const B &b) { return a<b ? a : b; }
00088 //template <class A> const A &MAX(const A &a,const B &b) { return a>b ? a : b; }
00089 
00090 //template <class A> const A &MIN(const A &a,const B &b,const C &c) { return a<b && a<c ? a : MIN(b,c); }
00091 //template <class A> const A &MAX(const A &a,const B &b,const C &c) { return a>b && a>c ? a : MAX(b,c); }
00092 
00093 #define MAX(x,y) (((x)>(y)) ? (x) : (y))
00094 #define MIN(x,y) (((x)<(y)) ? (x) : (y))
00095 
00096 #endif

Generated on Tue Nov 5 11:11:04 2002 for GLT by doxygen1.2.18