00001
00062 #ifndef INC_MI32_MATH_H
00063 #define INC_MI32_MATH_H
00064
00065 #ifndef INC_MI32_STDDEFNS_H
00066 #include <mi32/stddefns.h>
00067 #endif
00068
00069 #ifndef INC_MATH_H
00070 #ifndef GENERATING_DOXYGEN_OUTPUT
00071 #include <math.h>
00072 #define INC_MATH_H
00073 #endif
00074 #endif
00075
00076 #ifndef INC_CMATH
00077 #include <cmath>
00078 #define INC_CMATH
00079 #endif
00080
00081 #ifdef MISYSTEMDLL
00082 #define LIBEXPORT MI_DLLEXPORT
00083 #else
00084 #define LIBEXPORT MI_DLLIMPORT
00085 #endif
00086
00087
00090
00091 #if defined(__cplusplus)
00092 extern "C" {
00093 #endif
00094
00095 #ifndef GENERATING_DOXYGEN_OUTPUT
00096
00097 #if defined(WIN32)
00098 #if __STDC__ && _MSC_VER >= 1200
00099 #define hypot _hypot
00100 #endif
00101
00102 #elif !defined(LINUX)
00103 double hypot (double, double);
00104 #endif
00105
00106 #endif // GENERATING_DOXYGEN_OUTPUT
00107
00109 LIBEXPORT double IEEE_NaN (void);
00110
00112 LIBEXPORT double IEEE_Infinity (void);
00113
00114 #if defined(__cplusplus)
00115 }
00116 #endif
00117
00118
00119
00120 #define NEARINTADJ .0000001
00121
00122
00123
00124
00125
00133 inline INT32 FAST_CEIL (double x) {
00134 #if defined(WIN32) && defined(__cplusplus) && !defined(WIN64)
00135 static const double d = .4999999999;
00136 INT32 result;
00137 __asm fld x
00138 __asm fadd d
00139 __asm fistp result
00140 return result;
00141 #else
00142 return (static_cast<INT32>(ceil(x)));
00143 #endif
00144 }
00145
00146
00154 inline INT32 FAST_CEIL_NEARINT (double x) {
00155 #if defined(WIN32) && defined(__cplusplus) && !defined(WIN64)
00156 static const double d = .4999998;
00157 INT32 result;
00158 __asm fld x
00159 __asm fadd d
00160 __asm fistp result
00161 return result;
00162 #else
00163 return (static_cast<INT32>(ceil(x-NEARINTADJ)));
00164 #endif
00165 }
00166
00167
00175 inline INT32 FAST_FLOOR (double x) {
00176 #if defined(WIN32) && defined(__cplusplus) && !defined(WIN64)
00177 static const double d = -.4999999999;
00178 INT32 result;
00179 __asm fld x
00180 __asm fadd d
00181 __asm fistp result
00182 return result;
00183 #else
00184 return (static_cast<INT32>(floor(x)));
00185 #endif
00186 }
00187
00188
00196 inline INT32 FAST_FLOOR_NEARINT (double x) {
00197 #if defined(WIN32) && defined(__cplusplus) && !defined(WIN64)
00198 static const double d = -.4999998;
00199 INT32 result;
00200 __asm fld x
00201 __asm fadd d
00202 __asm fistp result
00203 return result;
00204 #else
00205 return (static_cast<INT32>(floor(x+NEARINTADJ)));
00206 #endif
00207 }
00208
00212 inline INT32 FAST_ROUND_EXACT (double x) {
00213 if (x < 0) {
00214 return (-static_cast<INT32>(-x+.5));
00215 }
00216 else {
00217 return (static_cast<INT32>(x+.5));
00218 }
00219 }
00220
00229 inline INT32 FAST_ROUND_NOLIMIT (double x) {
00230 #if defined(WIN32) && defined(__cplusplus) && !defined(WIN64)
00231 static const double d = 1E-10;
00232 INT32 result;
00233 __asm fld x
00234 __asm fadd d
00235 __asm fistp result
00236 return result;
00237 #else
00238 if (x < 0) {
00239 return (-static_cast<INT32>(-x+.5));
00240 }
00241 else {
00242 return (static_cast<INT32>(x+.5));
00243 }
00244 #endif
00245 }
00246
00251 inline INT32 FAST_ROUND_LIMITED (double x) {
00252 return (static_cast<INT32>(x+1000000.5)-1000000);
00253 }
00254
00257 inline INT32 FAST_ROUND_POSITIVE (double x) {
00258 return (static_cast<INT32>(x+.5));
00259 }
00260
00263 inline INT32 FAST_TRUNCATE (double x) {
00264 return (static_cast<INT32>(x));
00265 }
00266
00268 inline INT32 FAST_TRUNCATE_NEARINT (double x) {
00269 return (static_cast<INT32>(x+NEARINTADJ));
00270 }
00271
00272
00273 #undef NEARINTADJ
00274
00275
00276 #define FAST_ROUND FAST_ROUND_EXACT
00277 #ifdef WIN32
00278 #pragma deprecated("FAST_ROUND")
00279 #endif
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 #if defined(BYTEORDER_HiLo)
00291 #if defined(__cplusplus)
00292 inline bool IsNaN (double x) {return ((reinterpret_cast<UINT16*>(&x)[0] & 0x7FF8) == 0x7FF8);}
00293 #else
00294 #define IsNaN(x) ( ( ( (UINT16*)&(x) )[0] & 0x7FF8) == 0x7FF8)
00295 #endif
00296 #else
00297 #if defined(__cplusplus)
00298 inline bool IsNaN (const double& x) {return ((reinterpret_cast<const UINT16*>(&x)[3] & 0x7FF8) == 0x7FF8);}
00299 #else
00300 #define IsNaN(x) ( ( ( (UINT16*)&(x) )[3] & 0x7FF8) == 0x7FF8)
00301 #endif
00302 #endif
00303
00304
00305 #ifdef BYTEORDER_HiLo
00306 #if defined(__cplusplus)
00307 inline bool IsInfPos (double x) {return ((reinterpret_cast<UINT16*>(&x)[0] & 0x7FFF) == 0x7FF0);}
00308 #else
00309 #define IsInfPos(x) ( ( ( (UINT16*)&(x) )[0] & 0x7FFF) == 0x7FF0)
00310 #endif
00311 #else
00312 #if defined(__cplusplus)
00313 inline bool IsInfPos (double x) {return ((reinterpret_cast<UINT16*>(&x)[3] & 0x7FFF) == 0x7FF0);}
00314 #else
00315 #define IsInfPos(x) ( ( ( (UINT16*)&(x) )[3] & 0x7FFF) == 0x7FF0)
00316 #endif
00317 #endif
00318
00319 #ifdef BYTEORDER_HiLo
00320 #if defined(__cplusplus)
00321 inline bool IsInfNeg (double x) {return ((reinterpret_cast<UINT16*>(&x)[0] & 0xFFFF) == 0xFFF0);}
00322 #else
00323 #define IsInfNeg(x) ( ( ( (UINT16*)&(x) )[0] & 0xFFFF) == 0xFFF0)
00324 #endif
00325 #else
00326 #if defined(__cplusplus)
00327 inline bool IsInfNeg (double x) {return ((reinterpret_cast<UINT16*>(&x)[3] & 0xFFFF) == 0xFFF0);}
00328 #else
00329 #define IsInfNeg(x) ( ( ( (UINT16*)&(x) )[3] & 0xFFFF) == 0xFFF0)
00330 #endif
00331 #endif
00332
00333
00334 #ifndef NO_DEPRECATED
00335
00336 #ifndef NAN
00337
00338 #define NAN IEEE_NaN()
00339 #endif
00340
00341 #define IND IEEE_NaN()
00342 #define INF IEEE_Infinity()
00343 #define NINF (-IEEE_Infinity())
00344
00345 #ifdef WIN32
00346 #pragma deprecated("NAN")
00347 #pragma deprecated("IND")
00348 #pragma deprecated("INF")
00349 #pragma deprecated("NINF")
00350 #endif
00351
00352 #endif // NO_DEPRECATED
00353
00354
00356 void ConvIEEEToVAX (
00357 double ieee_value,
00358 UINT8 *vax_value
00359 );
00360
00364 double ConvVAXToIEEE (
00365 const UINT8 *vax_value
00366 );
00367
00370 int log2i (
00371 UINT32 value,
00372 bool roundup = true
00373 );
00374
00377 inline int log2i (
00378 INT32 value,
00379 bool roundup = true
00380 ) { return ((value > 0) ? log2i(static_cast<UINT32>(value),roundup) : -1); }
00381
00384 int log2i (
00385 UINT64 value,
00386 bool roundup = true
00387 );
00388
00391 inline int log2i (
00392 INT64 value,
00393 bool roundup = true
00394 ) { return ((value > 0) ? log2i(static_cast<UINT64>(value),roundup) : -1); }
00395
00397
00398 #undef LIBEXPORT
00399
00400 #endif // INC_MI32_MATH_H