VR-Forces 4.0.4 Class Documentation
include/tdbutil/mathUtilities.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2005 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: mathUtilities.h,v $ $Revision: 1.1 $ $State: Exp $
00007 *******************************************************************************/
00008 
00009 #ifndef mathUtilities_H_
00010 #define mathUtilities_H_
00011 
00012 #include <limits> // for floating point limits
00013 
00014 #ifndef WIN32
00015 #include <math.h>
00016 #endif
00017 
00018 #if WIN32
00019 // HACK - these are defined by stdlib.h and windef.h AS MACROS!
00020 // As a result, the walk over the std definition of min below.  So undefine
00021 // them first.
00022 #ifdef min
00023 static const int DtReDefineMin = 1;
00024 #undef min
00025 #else
00026 static const int DtReDefineMin = 0;
00027 #endif
00028 
00029 #ifdef max
00030 static const int DtReDefineMax = 1;
00031 #undef max
00032 #else
00033 static const int DtReDefineMax = 0;
00034 #endif
00035 
00036 #endif
00037 
00038 template <typename T>
00039 inline T DtMinValue()
00040 {
00041    return (std::numeric_limits<T>::min());
00042 }
00043 
00044 template <typename T>
00045 inline T DtMaxValue()
00046 {
00047    return (std::numeric_limits<T>::max());
00048 }
00049 
00050 #if WIN32
00051 // HACK - If we had to undefine it earlier, then redefine it now.
00052 #if DtReDefineMin
00053 #define min(a,b) (((a) < (b)) ? (a) : (b))
00054 #endif
00055 
00056 #if DtReDefineMax
00057 #define max(a,b) (((a) > (b)) ? (a) : (b))
00058 #endif
00059 
00060 #endif
00061 
00062 
00063 inline bool DtIsEven(int input)
00064 {
00065    if ((*reinterpret_cast<int*>(&input) & 0x0001)== 0)
00066    {
00067       return true;
00068    }
00069    else
00070    {
00071       return false;
00072    }
00073 }
00074 
00075 inline bool DtIsOdd(int input)
00076 {
00077    return !DtIsEven(input);
00078 }
00079 
00080 
00082 // FLOATING POINT UTILITY ROUTINES (COMPARISON, DIVIDE, ABSOLUTE VALUE...) 
00084 
00085 // @returns Result of comparison of input type with 0.  Specialized for
00086 // both single and double precision floating point numbers (float/double).
00087 template <typename T>
00088 inline bool DtIsZero(T input)
00089 {
00090    return (input == 0);
00091 }
00092 
00093 template <>
00094 inline bool DtIsZero<float>(float input)
00095 {
00096    return (fabs(input) < DtMinValue<float>());
00097 }
00098 
00099 template <>
00100 inline bool DtIsZero<double>(double input)
00101 {
00102    return (fabs(input) < DtMinValue<double>());
00103 }
00104 
00105 template <typename T>
00106 inline bool DtIsNotZero(T input)
00107 {
00108    return !DtIsZero(input);
00109 }
00110 
00111 
00112 #endif
00113 
00114 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)