17 #if !USE_STATIC_SECDESC_INIT 19 PISECURITY_DESCRIPTOR
pis;
21 SECURITY_DESCRIPTOR
DefSecDesc = { 0,0,0,NULL,NULL,NULL,NULL };
28 SECURITY_DESCRIPTOR_REVISION, 0,
45 #if 0 //defined(_MSC_VER) && (_WIN32_WINNT >= telephone_crap) 49 static DWORD _GetVersion(
void)
51 static DWORD (WINAPI *__GetVersion)(void) = NULL;
55 HMODULE hMod = GetModuleHandle(
"kernel32" );
56 if (hMod) (FARPROC&)__GetVersion = GetProcAddress( hMod,
"GetVersion" );
58 if (__GetVersion) version = __GetVersion();
61 OSVERSIONINFO vi; memset( &vi, 0,
sizeof(vi) );
62 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
63 if (GetVersionEx( &vi ))
65 version = (vi.dwMajorVersion & 0xFF) | ((vi.dwMinorVersion & 0xFF) << 8)
66 | (vi.dwBuildNumber << 16);
67 if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) version |= 0x80000000;
73 #define _GetVersion GetVersion 82 #define DW_HIGH_BIT 0x80000000L 84 DWORD version = _GetVersion();
87 if (isOk) isOk = (LOBYTE( LOWORD( version )) >= vMajor);
88 if (isOk) isOk = (HIBYTE( LOWORD( version )) >= vMinor);
104 #elif defined(_WIN32) 107 #error [uLib/Common] Please define IsWin64Bit for your platform. 116 BOOL isWow64 = FALSE;
117 static BOOL (WINAPI *_IsWow64Process)( HANDLE hProc, PBOOL pWow64Proc );
121 if (!_IsWow64Process)
123 HMODULE hKernel = GetModuleHandle(_T(
"KERNEL32"));
124 (FARPROC&)_IsWow64Process = GetProcAddress( hKernel,
"IsWow64Process" );
127 if (!_IsWow64Process( GetCurrentProcess(), &isWow64 ))
137 if (
IsWow64()) GetNativeSystemInfo( si );
138 else GetSystemInfo( si );
145 long map(
long x,
long xMin,
long xMax,
long toMin,
long toMax )
148 return toMin + (
INT64( x - xMin ) *
INT64( toMax - toMin )) / (xMax - xMin);
153 return (x > hi ? hi : (x < lo ? lo : x));
158 #if 0 // map can be used, but is overkill in ths case. 159 return map( rand(), 0, RAND_MAX, iMin, iMax );
161 int range = iMax - iMin;
162 return short( iMin + rand() * range / RAND_MAX );
170 QueryPerformanceCounter( &li );
178 return (X + ((Period-1)*Avg)) / Period;
197 #if 0 // Original loop, gets slowish for large X. 201 while( X >>= 1 ) y++;
204 #else // This algorithm is up to 3.7 times faster for large X :) 210 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n 211 #pragma pack( push, 1 ) 212 static const int8 Logs[256] =
214 #if 1 // Standard norm -- ilog2(0) == -1. 215 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
216 #else // As old one -- Non-standard -- ilog(0) == 0. 217 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
224 register ulong tmp, t2;
231 ilog = (t2 = tmp >> 8) ? 24 + Logs[ t2 ] : 16 + Logs[ tmp ];
235 ilog = (t2 = X >> 8) ? 8 + Logs[ t2 ] : Logs[ X ];
258 static ulong const Pwr10[] =
260 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
266 _ASSERTE( est <
dimof(Pwr10) );
267 ilog =
ushort( est - (X < Pwr10[ est ]) );
277 static uint64 const Pwr10[] =
279 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000,
280 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000,
281 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000,
282 10000000000000000000ul
288 _ASSERTE( est <
dimof(Pwr10) );
289 ilog =
ushort( est - (X < Pwr10[ est ]) );
296 long double _root(
long double base,
long double x )
298 return powl( x, (
long double)1.0L / base );
303 long double _log(
long double base,
long double x )
305 return logl( x ) / logl( base );
316 #if 0 // Use pow() -- expensive. 317 #define _HIGH_PRECISION 0 // Didn't alleviate LSB error :( 318 double _round(
double x,
unsigned char ndecimals )
323 unsigned int _pc = _control87( 0,0 ) & _MCW_PC;
324 _control87( _PC_64, _MCW_PC );
327 if (ndecimals > 15) ndecimals = 15;
328 if (ndecimals > 13) ndecimals = 13;
331 static const double _half = 0.5L;
332 double k = pow( 10.0, ndecimals );
333 x = (double) ceil( x * k - _half) / k;
336 _control87( _pc, _MCW_PC );
341 #undef _HIGH_PRECISION 343 double _round(
double x,
unsigned char ndeci )
345 static const double _half = 0.5L;
347 static const double _pwr[] = {
348 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0,
349 100000000.0, 1000000000.0, 10000000000.0, 100000000000.0,
350 1000000000000.0, 10000000000000.0, 100000000000000.0
355 if (!ndeci) x = (int) x;
359 double k = _pwr[ ndeci-1 ];
360 x = ceil( x * k - _half) / k;
376 if (x < 2)
return false;
377 if ((x % 2) == 0)
return (x == 2);
378 if ((x % 3) == 0)
return (x == 3);
379 if ((x % 5) == 0)
return (x == 5);
381 unsigned long n, limit = (
unsigned long) sqrt(
double( x ));
382 for( n = 7; n <= limit; n++ )
398 while( ++i )
if (
_isprime( x+i ))
return x+i;
410 unsigned long j = x + i;
414 if ((j > 2) &&
_isprime( j ))
return j;
426 #if !HAVE_BSWAP16_INTRINSIC 431 return (W << 8) | (W >> 8);
436 #if !HAVE_BSWAP32_INTRINSIC 441 return (DW << 24) | (DW >> 24)
442 | ((DW & 0x00FF0000) >> 8) | ((DW & 0x0000FF00) << 8);
447 #if !HAVE_BSWAP64_INTRINSIC 458 for(
BYTE i=0, j=7; i < 4; ++i, --j )
460 BYTE _b = u.b[i]; u.b[i] = u.b[j]; u.b[j] = _b;
short random(short iMin, short iMax)
UINT64 __cdecl _bswap64(UINT64 Val)
long double _log(long double base, long double x)
UINT16 __cdecl _bswap16(UINT16 W)
unsigned long _prime(unsigned long x)
Return nearest prime number not smaller than x.
UINT32 __cdecl _bswap32(UINT32 DW)
bool IsWinVer(BYTE vMajor, BYTE vMinor, bool winNt)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
bool _isprime(unsigned long x)
void GetWinSystemInfo(SYSTEM_INFO *si)
PISECURITY_DESCRIPTOR pis
SECURITY_DESCRIPTOR DefSecDesc
long constrain(long x, long lo, long hi)
long runningAvg(long Avg, long X, unsigned int Period)
SECURITY_ATTRIBUTES DefSec
bool __forceinline bool_cast(BOOL B52)
double _round(double x, unsigned char ndeci)
long map(long x, long xMin, long xMax, long toMin, long toMax)
long double _root(long double base, long double x)
Common include; Added types, small "ubiquitous" utilities, et c.
unsigned long _nearprime(unsigned long x)
Return nearest prime above or below x, or precisely x.