Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
csqint.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998-2000 by Andrew Zabolotny 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSQINT_H__ 00020 #define __CS_CSQINT_H__ 00021 00022 #if defined (CS_IEEE_DOUBLE_FORMAT) 00023 00110 #ifdef CS_BIG_ENDIAN 00111 # define CS_LOWER_WORD_BYTE 4 00112 #else 00113 # define CS_LOWER_WORD_BYTE 0 00114 #endif 00115 00116 #define CS_LONG_AT_BYTE(x,b) *(long *)(((char *)&x) + b) 00117 00124 #define FIST_MAGIC_QINT (65536.0 * 65536.0 * 16.0) 00125 00132 #ifdef CS_QINT_WORKAROUND 00133 static inline long csQint (double inval) 00134 { 00135 union { double dtemp; long result; } x; 00136 00137 x.dtemp = FIST_MAGIC_QINT + inval; 00138 x.result = CS_LONG_AT_BYTE (x.dtemp, 2); 00139 return x.result < 0 ? (x.result >> 1) + 1 : x.result; 00140 } 00141 #else 00142 static inline long csQint (double inval) 00143 { 00144 double dtemp = FIST_MAGIC_QINT + inval; 00145 // Note that on both low-endian (x86) and big-endian (m68k) we have 00146 // to shift by two bytes. So no need for an #ifdef. 00147 long result = CS_LONG_AT_BYTE (dtemp, 2); 00148 return result < 0 ? (result >> 1) + 1 : result; 00149 } 00150 #endif 00151 00156 #define FIST_MAGIC_QROUND (((65536.0 * 65536.0 * 16.0) + (65536.0 * 0.5)) * 65536.0) 00157 00161 #ifdef CS_QINT_WORKAROUND 00162 static inline long csQround (double inval) 00163 { 00164 union { double dtemp; long result; } x; 00165 00166 x.dtemp = (FIST_MAGIC_QINT + 0.5f) + inval; 00167 x.result = CS_LONG_AT_BYTE (x.dtemp, 2); 00168 return x.result < 0 ? (x.result >> 1) + 1 : x.result; 00169 } 00170 #else 00171 static inline long csQround (double inval) 00172 { 00173 double dtemp = FIST_MAGIC_QROUND + inval; 00174 return CS_LONG_AT_BYTE (dtemp, CS_LOWER_WORD_BYTE) - 0x80000000; 00175 } 00176 #endif 00177 00182 #define FIST_MAGIC_QINT8 (((65536.0 * 16.0) + 0.5) * 65536.0 * 256.0) 00183 00185 #ifdef CS_QINT_WORKAROUND 00186 inline long csQint8 (float inval) 00187 { 00188 union { double dtemp; long result; } x; 00189 00190 x.dtemp = FIST_MAGIC_QINT8 + inval; 00191 x.result = CS_LONG_AT_BYTE (x.dtemp, CS_LOWER_WORD_BYTE); 00192 return x.result - 0x80000000; 00193 } 00194 #else 00195 inline long csQint8 (float inval) 00196 { 00197 double dtemp = FIST_MAGIC_QINT8 + inval; 00198 return CS_LONG_AT_BYTE (dtemp, CS_LOWER_WORD_BYTE) - 0x80000000; 00199 } 00200 #endif 00201 00206 #define FIST_MAGIC_QINT16 (((65536.0 * 16.0) + 0.5) * 65536.0) 00207 00209 #ifdef CS_QINT_WORKAROUND 00210 inline long csQint16 (float inval) 00211 { 00212 union { double dtemp; long result; } x; 00213 00214 x.dtemp = FIST_MAGIC_QINT16 + inval; 00215 x.result = CS_LONG_AT_BYTE (x.dtemp, CS_LOWER_WORD_BYTE); 00216 return x.result - 0x80000000; 00217 } 00218 #else 00219 inline long csQint16 (float inval) 00220 { 00221 double dtemp = FIST_MAGIC_QINT16 + inval; 00222 return CS_LONG_AT_BYTE (dtemp, CS_LOWER_WORD_BYTE) - 0x80000000; 00223 } 00224 #endif 00225 00230 #define FIST_MAGIC_QINT24 (((65536.0 * 16.0) + 0.5) * 256.0) 00231 00233 #ifdef CS_QINT_WORKAROUND 00234 inline long csQint24 (float inval) 00235 { 00236 union { double dtemp; long result; } x; 00237 00238 x.dtemp = FIST_MAGIC_QINT24 + inval; 00239 x.result = CS_LONG_AT_BYTE (x.dtemp, CS_LOWER_WORD_BYTE); 00240 return x.result - 0x80000000; 00241 } 00242 #else 00243 inline long csQint24 (float inval) 00244 { 00245 double dtemp = FIST_MAGIC_QINT24 + inval; 00246 return CS_LONG_AT_BYTE (dtemp, CS_LOWER_WORD_BYTE) - 0x80000000; 00247 } 00248 #endif 00249 00252 #else /* not CS_IEEE_DOUBLE_FORMAT */ 00253 00254 static inline long csQround (double inval) 00255 { 00256 return int (inval + ((inval < 0) ? -0.5 : +0.5)); 00257 } 00258 #define csQint(x) (int (x)) 00259 #define csQint8(x) (int ((x)*256.)) 00260 #define csQint16(x) (int ((x)*65536.)) 00261 #define csQint24(x) (int ((x)*16777216.)) 00262 00263 #endif /* CS_IEEE_DOUBLE_FORMAT */ 00264 00265 #endif // __CS_CSQINT_H__
Generated for Crystal Space by doxygen 1.3.9.1