1 #pragma once 2 3 C_ASSERT(sizeof(FIX) == sizeof(LONG)); 4 #define FIX2LONG(x) (((x) + 8) >> 4) 5 #define LONG2FIX(x) ((x) << 4) 6 7 #if defined(_M_IX86) 8 9 FORCEINLINE 10 BOOL 11 _FLOATOBJ_Equal(FLOATOBJ *pf1, FLOATOBJ *pf2) 12 { 13 EFLOAT_S *pef1 = (EFLOAT_S*)pf1; 14 EFLOAT_S *pef2 = (EFLOAT_S*)pf2; 15 return (pef1->lMant == pef2->lMant && pef1->lExp == pef2->lExp); 16 } 17 #define FLOATOBJ_Equal _FLOATOBJ_Equal 18 19 FORCEINLINE 20 LONG 21 _FLOATOBJ_GetLong(FLOATOBJ *pf) 22 { 23 EFLOAT_S *pef = (EFLOAT_S*)pf; 24 return pef->lMant >> (32 - pef->lExp); 25 } 26 #define FLOATOBJ_GetLong _FLOATOBJ_GetLong 27 28 /*! 29 * \brief Converts a FLOATOBJ into a LONG by truncating the value to integer 30 * 31 * \param pf - Pointer to a FLOATOBJ containing the value to convert 32 * 33 * \param pl - Pointer to a variable that receives the result 34 * 35 * \return TRUE if the function succeeded, FALSE if the result would overflow 36 * a LONG. 37 */ 38 FORCEINLINE 39 BOOL 40 FASTCALL 41 FLOATOBJ_bConvertToLong(FLOATOBJ *pf, PLONG pl) 42 { 43 EFLOAT_S *pef = (EFLOAT_S*)pf; 44 LONG lShift = 32 - pef->lExp; 45 if (lShift < 0) 46 { 47 return FALSE; 48 } 49 *pl = pef->lMant >> lShift; 50 return TRUE; 51 } 52 53 FORCEINLINE 54 LONG 55 FLOATOBJ_GetFix(FLOATOBJ *pf) 56 { 57 EFLOAT_S *pef = (EFLOAT_S*)pf; 58 LONG Shift = (28 - pef->lExp); 59 return (Shift >= 0 ? pef->lMant >> Shift : pef->lMant << -Shift); 60 } 61 62 FORCEINLINE 63 BOOL 64 FLOATOBJ_IsLong(FLOATOBJ *pf) 65 { 66 EFLOAT_S *pef = (EFLOAT_S*)pf; 67 ULONG ulShift = pef->lExp; 68 if (ulShift < 32) 69 return ((pef->lMant << ulShift) == 0); 70 else 71 return (ulShift == 32); 72 } 73 74 FORCEINLINE 75 BOOL 76 FLOATOBJ_Equal0(FLOATOBJ *pf) 77 { 78 EFLOAT_S *pef = (EFLOAT_S*)pf; 79 return (pef->lMant == 0 && pef->lExp == 0); 80 } 81 82 FORCEINLINE 83 BOOL 84 FLOATOBJ_Equal1(FLOATOBJ *pf) 85 { 86 EFLOAT_S *pef = (EFLOAT_S*)pf; 87 return (pef->lMant == 0x40000000 && pef->lExp == 2); 88 } 89 90 extern const FLOATOBJ gef0; 91 extern const FLOATOBJ gef1; 92 extern const FLOATOBJ gef16; 93 94 #define FLOATOBJ_0 {0x00000000, 0x00000000} 95 #define FLOATOBJ_1 {0x40000000, 0x00000002} 96 #define FLOATOBJ_16 {0x40000000, 0x00000006} 97 #define FLOATOBJ_1_16 {0x40000000, 0xfffffffe} 98 99 #define FLOATOBJ_Set0(fo) do { (fo)->ul1 = 0; (fo)->ul2 = 0; } while (0) 100 #define FLOATOBJ_Set1(fo) do { (fo)->ul1 = 0x40000000; (fo)->ul2 = 2; } while (0) 101 102 #else 103 104 #define FLOATOBJ_bConvertToLong(pf, pl) (*pl = (LONG)*pf, TRUE) 105 #define FLOATOBJ_IsLong(pf) ((FLOAT)((LONG)*(pf)) == *(pf)) 106 #define FLOATOBJ_Equal0(pf) (*(pf) == 0.) 107 #define FLOATOBJ_Equal1(pf) (*(pf) == 1.) 108 #define FLOATOBJ_GetFix(pf) ((LONG)(*(pf) * 16.)) 109 110 #define FLOATOBJ_0 0. 111 #define FLOATOBJ_1 1. 112 #define FLOATOBJ_16 16. 113 #define FLOATOBJ_1_16 (1./16.) 114 115 static const FLOATOBJ gef0 = 0.; 116 static const FLOATOBJ gef1 = 1.; 117 static const FLOATOBJ gef16 = 16.; 118 119 #define FLOATOBJ_Set0(fo) *(fo) = 0; 120 #define FLOATOBJ_Set1(fo) *(fo) = 1; 121 122 #endif 123