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

real.inl

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 bool feq(Real a, Real b, Real e /*= EPS*/) {
00025     if(a == 0 && fabs(b) < e)
00026         return true;
00027 
00028     if(b == 0 && fabs(a) < e)
00029         return true;
00030 
00031     return fabs(a - b) < e * fabs(a);
00032 }
00033 
00034 inline
00035 bool fneq(Real a, Real b, Real e /*= EPS*/) {
00036     return !feq(a, b, e);
00037 }
00038 
00039 inline
00040 bool fle(Real a, Real b, Real e /*= EPS*/) {
00041     return a < b || feq(a, b, e);
00042 }
00043 
00044 inline
00045 bool fge(Real a, Real b, Real e /*= EPS*/) {
00046     return a > b || feq(a, b, e);
00047 }
00048 
00049 inline
00050 bool fz(Real a, Real e /*= EPS*/) {
00051     return fabs(a) < e;
00052 }
00053 
00054 inline
00055 bool fnz(Real a, Real e /*= EPS*/) {
00056     return fabs(a) >= e;
00057 }
00058 
00059 template<typename T> inline
00060 T sq(T x) {
00061     return x * x;
00062 }
00063 
00064 inline
00065 Real dtor(Real d) {
00066     return d * (PI / 180.0);
00067 }
00068 
00069 inline
00070 Real rtod(Real r) {
00071     return r * (180.0 / PI);
00072 }
00073 
00074 inline
00075 Real NormalizeAngle(Real angle) {
00076     angle = fmod(angle, 2.0 * PI);
00077     return angle < 0.0 ? angle + 2.0 * PI : angle;
00078 }
00079 
00080 inline
00081 int NextPowerOfTwo(double x) {
00082     assert(x >= 1.0);
00083     return 1 << static_cast<int>(ceil(log(x) / log(2.0)));
00084 }

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6