Changeset 1005 for cpp/common
- Timestamp:
- 07/14/20 15:54:43 (4 years ago)
- Location:
- cpp/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/Convert.cpp
r400 r1005 4 4 5 5 #include "Convert.h" 6 7 6 #include <sstream> 8 7 … … 91 90 struct tm ret; 92 91 #if defined LINUX // || android? 93 return *::localtime_r(&timep, &ret);92 return *::localtime_r(&timep, &ret); 94 93 #elif defined _WIN32 && !defined __BORLANDC__ 95 94 ::localtime_s(&ret, &timep); … … 97 96 #else //borland? 98 97 pthread_mutex_lock(&fix_unsafe_mutex); 99 ret =*::localtime(&timep);98 ret = *::localtime(&timep); 100 99 pthread_mutex_unlock(&fix_unsafe_mutex); 101 100 return ret; … … 110 109 #ifndef MULTITHREADED 111 110 112 ret =::asctime(&tm);111 ret = ::asctime(&tm); 113 112 114 113 #else //MULTITHREADED … … 116 115 char buf[26]; 117 116 #if defined LINUX // || android? 118 ret =::asctime_r(&tm,buf);117 ret = ::asctime_r(&tm, buf); 119 118 #elif defined _WIN32 && !defined __BORLANDC__ 120 119 asctime_s(buf, sizeof(buf), &tm); … … 122 121 #else //borland? 123 122 pthread_mutex_lock(&fix_unsafe_mutex); 124 strcpy(buf, ::asctime(&tm));125 ret =buf;123 strcpy(buf, ::asctime(&tm)); 124 ret = buf; 126 125 pthread_mutex_unlock(&fix_unsafe_mutex); 127 126 #endif -
cpp/common/Convert.h
r913 r1005 11 11 #include "2d.h" 12 12 #include <stdint.h> 13 #include <cmath> 13 14 14 15 … … 39 40 static uint32_t hexToInt(const string& col); 40 41 41 static double toRadians(double angle) { return angle *M_PI / 180; }42 static double toRadians(double angle) { return angle * M_PI / 180; } 42 43 static double toDegrees(double angle) { return angle / M_PI * 180; } 43 44 static double atan_2(double y, double x) { if (x == 0 && y == 0) return 0; else return atan2(y, x); } //needed by borland 5/6 only? … … 46 47 { 47 48 double dx = x2 - x1, dy = y2 - y1; 48 return dx *dx + dy*dy;49 return dx * dx + dy * dy; 49 50 } 50 51 static double odleglosc_sq(const Pt2D& p1, const Pt2D& p2) //odleglosc do kwadratu … … 53 54 } 54 55 55 static double odleglosc(double x1, double y1, double x2, double y2) 56 static double odleglosc(double x1, double y1, double x2, double y2) { return sqrt(odleglosc_sq(x1, y1, x2, y2)); } 56 57 static double odleglosc(const Pt2D& p1, const Pt2D& p2) 57 58 { -
cpp/common/random.h
r896 r1005 6 6 7 7 #ifdef _MSC_VER 8 9 10 8 #define NOMINMAX //we don't want Windows headers (minwindef.h) to define min() and max() as macros 9 #undef min //for some reason, NOMINMAX did not work so we have to #undef anyway 10 #undef max 11 11 #endif 12 12 … … 14 14 #include <stdint.h> //uintptr_t 15 15 #ifdef MULTITHREADED 16 16 #include "threads.h" 17 17 #endif 18 18 #ifdef LINUX 19 20 21 19 #include <unistd.h> 20 #include <sys/stat.h> 21 #include <fcntl.h> 22 22 #endif 23 23 #ifdef _WIN32 24 25 26 24 #define _WINSOCKAPI_ //http://stackoverflow.com/questions/1372480/c-redefinition-header-files 25 #include <rpc.h> //UUID 26 #pragma comment(lib, "Rpcrt4.lib") 27 27 #endif 28 28 … … 63 63 mt[0] = seed; 64 64 for (unsigned int i = 1; i < length; i++) 65 mt[i] = (1812433253 * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i) &bitMask_32;65 mt[i] = (1812433253 * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i) & bitMask_32; 66 66 #ifdef MULTITHREADED 67 67 pthread_mutex_unlock(&lock); … … 74 74 //for ms visual, could use http://msdn.microsoft.com/en-us/library/sxtz2fa8.aspx 75 75 #ifdef LINUX 76 int fd =open("/dev/urandom",O_RDONLY);77 if (fd >=0)76 int fd = open("/dev/urandom", O_RDONLY); 77 if (fd >= 0) 78 78 { 79 read(fd, &seed,sizeof(seed));79 read(fd, &seed, sizeof(seed)); 80 80 close(fd); 81 81 } … … 84 84 { 85 85 counter++; 86 seed = (unsigned int)time(NULL); 86 seed = (unsigned int)time(NULL); //time (seconds); could use hi-res timer but then we would depend on common/timer.h 87 87 seed ^= counter; //incremented value, possibly randomly initialized 88 88 seed ^= (unsigned int)(uintptr_t)&counter; //memory address … … 91 91 UUID uuid; 92 92 ::UuidCreate(&uuid); 93 seed ^= uuid.Data1 ^uuid.Data2^uuid.Data3^uuid.Data4[0];93 seed ^= uuid.Data1 ^ uuid.Data2 ^ uuid.Data3 ^ uuid.Data4[0]; 94 94 #endif 95 95 setSeed(seed); … … 117 117 //UniformRandomBitGenerator 118 118 typedef unsigned int result_type; 119 static constexpr unsigned int min() { return 0;}120 static constexpr unsigned int max() { return MAXVALUE;}121 inline unsigned int operator()() { return getUint32();}119 static constexpr unsigned int min() { return 0; } 120 static constexpr unsigned int max() { return MAXVALUE; } 121 inline unsigned int operator()() { return getUint32(); } 122 122 123 123 inline double getDouble() // [0,1)
Note: See TracChangeset
for help on using the changeset viewer.