VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mathUtilities.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2005 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: mathUtilities.h,v $ $Revision: 1.1 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef mathUtilities_H_
10 #define mathUtilities_H_
11 
12 #include <limits> // for floating point limits
13 
14 #ifndef WIN32
15 #include <math.h>
16 #endif
17 
18 #if WIN32
19 // HACK - these are defined by stdlib.h and windef.h AS MACROS!
20 // As a result, the walk over the std definition of min below. So undefine
21 // them first.
22 #ifdef min
23 static const int DtReDefineMin = 1;
24 #undef min
25 #else
26 static const int DtReDefineMin = 0;
27 #endif
28 
29 #ifdef max
30 static const int DtReDefineMax = 1;
31 #undef max
32 #else
33 static const int DtReDefineMax = 0;
34 #endif
35 
36 #endif
37 
38 template <typename T>
39 inline T DtMinValue()
40 {
41  return (std::numeric_limits<T>::min());
42 }
43 
44 template <typename T>
45 inline T DtMaxValue()
46 {
47  return (std::numeric_limits<T>::max());
48 }
49 
50 #if WIN32
51 // HACK - If we had to undefine it earlier, then redefine it now.
52 #if DtReDefineMin
53 #define min(a,b) (((a) < (b)) ? (a) : (b))
54 #endif
55 
56 #if DtReDefineMax
57 #define max(a,b) (((a) > (b)) ? (a) : (b))
58 #endif
59 
60 #endif
61 
62 
63 inline bool DtIsEven(int input)
64 {
65  if ((*reinterpret_cast<int*>(&input) & 0x0001)== 0)
66  {
67  return true;
68  }
69  else
70  {
71  return false;
72  }
73 }
74 
75 inline bool DtIsOdd(int input)
76 {
77  return !DtIsEven(input);
78 }
79 
80 
82 // FLOATING POINT UTILITY ROUTINES (COMPARISON, DIVIDE, ABSOLUTE VALUE...)
84 
85 // @returns Result of comparison of input type with 0. Specialized for
86 // both single and double precision floating point numbers (float/double).
87 template <typename T>
88 inline bool DtIsZero(T input)
89 {
90  return (input == 0);
91 }
92 
93 template <>
94 inline bool DtIsZero<float>(float input)
95 {
96  return (fabs(input) < DtMinValue<float>());
97 }
98 
99 template <>
100 inline bool DtIsZero<double>(double input)
101 {
102  return (fabs(input) < DtMinValue<double>());
103 }
104 
105 template <typename T>
106 inline bool DtIsNotZero(T input)
107 {
108  return !DtIsZero(input);
109 }
110 
111 
112 #endif
113 
114 
bool DtIsNotZero(T input)
Definition: mathUtilities.h:106
T DtMaxValue()
Definition: mathUtilities.h:45
bool DtIsZero< float >(float input)
Definition: mathUtilities.h:94
bool DtIsZero< double >(double input)
Definition: mathUtilities.h:100
bool DtIsEven(int input)
Definition: mathUtilities.h:63
T DtMinValue()
Definition: mathUtilities.h:39
bool DtIsZero(T input)
Definition: mathUtilities.h:88
bool DtIsOdd(int input)
Definition: mathUtilities.h:75

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)