00001 /*------------------------------------------------------------------------------ 00002 00003 Octree Component, version 2.1 00004 Copyright (c) 2004-2007, Harrison Ainsworth / HXA7241. 00005 00006 http://www.hxa7241.org/ 00007 00008 ------------------------------------------------------------------------------*/ 00009 00010 /*------------------------------------------------------------------------------ 00011 00012 Copyright (c) 2004-2007, Harrison Ainsworth / HXA7241. 00013 00014 Redistribution and use in source and binary forms, with or without modification, 00015 are permitted provided that the following conditions are met: 00016 00017 * Redistributions of source code must retain the above copyright notice, this 00018 list of conditions and the following disclaimer. 00019 * Redistributions in binary form must reproduce the above copyright notice, this 00020 list of conditions and the following disclaimer in the documentation and/or 00021 other materials provided with the distribution. 00022 * The name of the author may not be used to endorse or promote products derived 00023 from this software without specific prior written permission. 00024 00025 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 00026 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00027 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00028 SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00030 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00031 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00032 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00033 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00034 OF SUCH DAMAGE. 00035 00036 ------------------------------------------------------------------------------*/ 00037 00038 00039 #ifndef Primitives_h 00040 #define Primitives_h 00041 00042 00043 #include <limits.h> 00044 #include <float.h> 00045 00046 00047 00048 00049 namespace hxa7241 00050 { 00051 00052 00054 00055 // remove definition to set real to double 00056 //#define REAL_IS_FLOAT 00057 00058 typedef signed char byte; 00059 typedef unsigned char ubyte; 00060 00061 typedef signed short word; 00062 typedef unsigned short uword; 00063 00064 typedef signed int dword; 00065 typedef unsigned int udword; 00066 00067 #ifdef REAL_IS_FLOAT 00068 typedef float real; 00069 #else 00070 typedef double real; 00071 #endif 00072 00073 00075 00076 // limits.h version 00077 00078 const byte BYTE_MIN = SCHAR_MIN; 00079 const byte BYTE_MAX = SCHAR_MAX; 00080 const int BYTE_BITS = 8; 00081 00082 const ubyte UBYTE_MIN = 0; 00083 const ubyte UBYTE_MAX = UCHAR_MAX; 00084 const int UBYTE_BITS = 8; 00085 00086 00087 const word WORD_MIN = SHRT_MIN; 00088 const word WORD_MAX = SHRT_MAX; 00089 const int WORD_BITS = 16; 00090 00091 const uword UWORD_MIN = 0; 00092 const uword UWORD_MAX = USHRT_MAX; 00093 const int UWORD_BITS = 16; 00094 00095 00096 const dword DWORD_MIN = INT_MIN; 00097 const dword DWORD_MAX = INT_MAX; 00098 const int DWORD_BITS = 32; 00099 00100 const udword UDWORD_MIN = 0; 00101 const udword UDWORD_MAX = UINT_MAX; 00102 const int UDWORD_BITS = 32; 00103 00104 00105 const float FLOAT_MIN_POS = static_cast<float>(FLT_MIN); 00106 const float FLOAT_MIN_NEG = static_cast<float>(-FLT_MAX); 00107 const float FLOAT_MAX = static_cast<float>(FLT_MAX); 00108 const float FLOAT_EPSILON = static_cast<float>(FLT_EPSILON); 00109 const float FLOAT_ALMOST_ONE = static_cast<float>(1.0f - FLT_EPSILON); 00110 const float FLOAT_SMALL = static_cast<float>(1.0e-12f); 00111 const float FLOAT_LARGE = static_cast<float>(1.0e+12f); 00112 00113 const double DOUBLE_MIN_POS = static_cast<double>(DBL_MIN); 00114 const double DOUBLE_MIN_NEG = static_cast<double>(-DBL_MAX); 00115 const double DOUBLE_MAX = static_cast<double>(DBL_MAX); 00116 const double DOUBLE_EPSILON = static_cast<double>(DBL_EPSILON); 00117 const double DOUBLE_ALMOST_ONE = static_cast<double>(1.0 - DBL_EPSILON); 00118 const double DOUBLE_SMALL = static_cast<double>(1.0e-96); 00119 const double DOUBLE_LARGE = static_cast<double>(1.0e+96); 00120 00121 #ifdef REAL_IS_FLOAT 00122 const float REAL_MIN_POS = FLOAT_MIN_POS; 00123 const float REAL_MIN_NEG = FLOAT_MIN_NEG; 00124 const float REAL_MAX = FLOAT_MAX; 00125 const float REAL_EPSILON = FLOAT_EPSILON; 00126 const float REAL_ALMOST_ONE = FLOAT_ALMOST_ONE; 00127 const float REAL_SMALL = FLOAT_SMALL; 00128 const float REAL_LARGE = FLOAT_LARGE; 00129 #else 00130 const double REAL_MIN_POS = DOUBLE_MIN_POS; 00131 const double REAL_MIN_NEG = DOUBLE_MIN_NEG; 00132 const double REAL_MAX = DOUBLE_MAX; 00133 const double REAL_EPSILON = DOUBLE_EPSILON; 00134 const double REAL_ALMOST_ONE = DOUBLE_ALMOST_ONE; 00135 const double REAL_SMALL = DOUBLE_SMALL; 00136 const double REAL_LARGE = DOUBLE_LARGE; 00137 #endif 00138 00139 00140 // limits version 00141 00142 /* 00143 const byte BYTE_MIN = std::numeric_limits<byte>::min(); 00144 const byte BYTE_MAX = std::numeric_limits<byte>::max(); 00145 const int BYTE_BITS = 8; 00146 00147 const ubyte UBYTE_MIN = std::numeric_limits<ubyte>::min(); 00148 const ubyte UBYTE_MAX = std::numeric_limits<ubyte>::max(); 00149 const int UBYTE_BITS = 8; 00150 00151 00152 const word WORD_MIN = std::numeric_limits<word>::min(); 00153 const word WORD_MAX = std::numeric_limits<word>::max(); 00154 const int WORD_BITS = 16; 00155 00156 const uword UWORD_MIN = std::numeric_limits<uword>::min(); 00157 const uword UWORD_MAX = std::numeric_limits<uword>::max(); 00158 const int UWORD_BITS = 16; 00159 00160 00161 const dword DWORD_MIN = std::numeric_limits<dword>::min(); 00162 const dword DWORD_MAX = std::numeric_limits<dword>::max(); 00163 const int DWORD_BITS = 32; 00164 00165 const udword UDWORD_MIN = std::numeric_limits<udword>::min(); 00166 const udword UDWORD_MAX = std::numeric_limits<udword>::max(); 00167 const int UDWORD_BITS = 32; 00168 00169 00170 const float FLOAT_MIN_POS = std::numeric_limits<float>::min(); 00171 const float FLOAT_MIN_NEG = 00172 static_cast<float>(-std::numeric_limits<float>::max()); 00173 const float FLOAT_MAX = std::numeric_limits<float>::max(); 00174 const float FLOAT_EPSILON = std::numeric_limits<float>::epsilon(); 00175 const float FLOAT_ALMOST_ONE = 00176 static_cast<float>(1.0f - std::numeric_limits<float>::epsilon()); 00177 const float FLOAT_SMALL = static_cast<float>(1.0e-12f); 00178 const float FLOAT_LARGE = static_cast<float>(1.0e+12f); 00179 00180 const double DOUBLE_MIN_POS = std::numeric_limits<double>::min(); 00181 const double DOUBLE_MIN_NEG = 00182 static_cast<double>(-std::numeric_limits<double>::max()); 00183 const double DOUBLE_MAX = std::numeric_limits<double>::max(); 00184 const double DOUBLE_EPSILON = std::numeric_limits<double>::epsilon(); 00185 const double DOUBLE_ALMOST_ONE = 00186 static_cast<double>(1.0 - std::numeric_limits<double>::epsilon()); 00187 const double DOUBLE_SMALL = static_cast<double>(1.0e-96); 00188 const double DOUBLE_LARGE = static_cast<double>(1.0e+96); 00189 00190 #ifdef REAL_IS_FLOAT 00191 const float REAL_MIN_POS = FLOAT_MIN_POS; 00192 const float REAL_MIN_NEG = FLOAT_MIN_NEG; 00193 const float REAL_MAX = FLOAT_MAX; 00194 const float REAL_EPSILON = FLOAT_EPSILON; 00195 const float REAL_ALMOST_ONE = FLOAT_ALMOST_ONE; 00196 const float REAL_SMALL = FLOAT_SMALL; 00197 const float REAL_LARGE = FLOAT_LARGE; 00198 #else 00199 const double REAL_MIN_POS = DOUBLE_MIN_POS; 00200 const double REAL_MIN_NEG = DOUBLE_MIN_NEG; 00201 const double REAL_MAX = DOUBLE_MAX; 00202 const double REAL_EPSILON = DOUBLE_EPSILON; 00203 const double REAL_ALMOST_ONE = DOUBLE_ALMOST_ONE; 00204 const double REAL_SMALL = DOUBLE_SMALL; 00205 const double REAL_LARGE = DOUBLE_LARGE; 00206 #endif 00207 */ 00208 00209 00210 }//namespace 00211 00212 00213 00214 00215 #endif//Primitives_h