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

mathematics.h

Go to the documentation of this file.
00001 //FILE:         mathematics.h
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00008 #ifndef COURNIA_MATHEMATICS_H
00009 #define COURNIA_MATHEMATICS_H 1 
00010 
00012 typedef float real_t;
00013 
00014 #include <cstdlib>
00015 #include <cmath>
00016 
00017 //#define MATH_EPSILON 1.19209290e-07f
00019 #define MATH_EPSILON 0.00001
00020 
00022 namespace math {
00023 
00025 inline double
00026 rand01( void ) 
00027 {
00028         return (rand( ) / (double)RAND_MAX);
00029 }
00030 
00032 
00036 inline double
00037 to_degrees( double x )
00038 {
00039         return (x * 180.0 / M_PI);
00040 }
00041 
00043 
00047 inline double
00048 to_radians( double x )
00049 {
00050         return (x * M_PI / 180.0);
00051 }
00052 
00054 
00058 inline bool
00059 equals( double x, double y ) 
00060 {
00061         return (std::fabs( x - y ) < MATH_EPSILON);
00062 }
00063 
00065 
00073 template <class T>
00074 inline void
00075 swap( T& x, T& y )
00076 {
00077         T z = x;
00078         x = y;
00079         y = z;
00080 }
00081 
00083 
00086 inline double
00087 sign( double x )
00088 {
00089         if( x < 0.0 ) {
00090                 return -1.0;
00091         } else {
00092                 return 1.0;
00093         }
00094 }
00095 
00097 
00100 inline bool
00101 same_sign( double x, double y )
00102 {
00103         if( x * y >= 0.0 ) {
00104                 return true;
00105         } else {
00106                 return false;
00107         }
00108 }
00109 
00111 
00114 inline bool
00115 negative( double x )
00116 {
00117         if( x < 0.0 ) {
00118                 return true;
00119         } else {
00120                 return false;
00121         }
00122 }
00123 
00125 
00128 inline bool
00129 positive( double x )
00130 {
00131         if( x < 0.0 ) {
00132                 return false;
00133         } else {
00134                 return true;
00135         }
00136 }
00137 
00138 } //end of namespace math
00139 
00140 #endif

Generated on Tue Feb 11 18:49:41 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002