Changeset 1005
- Timestamp:
- 07/14/20 15:54:43 (5 years ago)
- Location:
- cpp
- Files:
-
- 7 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) -
cpp/frams/_demos/simil_test.cpp
r1004 r1005 19 19 { 20 20 LoggerToStdout messages_to_stdout(LoggerBase::Enable); 21 typedef double *pDouble;22 21 int iCurrParam = 0; // index of the currently processed parameter 23 22 char *szCurrParam = NULL; … … 172 171 double **aaSimil = NULL; // array of similarities 173 172 174 // create theempty array of similarities175 aaSimil = new pDouble[pvGenos.size()];173 // create an empty array of similarities 174 aaSimil = new double*[pvGenos.size()]; 176 175 for (unsigned int k = 0; k < pvGenos.size(); k++) 177 176 { … … 181 180 } 182 181 183 // compute and remembersimilarities182 // compute and store similarities 184 183 for (unsigned int i = 0; i < pvGenos.size(); i++) 185 184 { … … 193 192 if (bPrintNames) 194 193 { 195 // if "-names" switch was given, print the number of genotypes and their names194 // if the "-names" switch was given, print the number of genotypes and their names 196 195 printf("%li\n", pvGenos.size()); 197 196 for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++) -
cpp/frams/genetics/f9/f9_oper.cpp
r974 r1005 6 6 #include "f9_conv.h" 7 7 #include <common/nonstd.h> //rndUint, rndDouble 8 #include <string.h> 8 9 9 10 -
cpp/frams/param/paramobj.cpp
r792 r1005 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 6 6 #include <frams/util/extvalue.h> 7 7 #include <common/nonstd_stl.h> 8 8 9 9 static const char* maybedup(bool dup, const char* src) 10 10 { -
cpp/frams/util/extvalue.cpp
r973 r1005 705 705 fpExceptDisable(); 706 706 double tmp = getDouble() / a; 707 if (! finite(tmp))707 if (!std::isfinite(tmp)) 708 708 { 709 709 logPrintf("ExtValue", "divide", LOG_ERROR, "Overflow %s/%g", getString().c_str(), a); setInvalid();
Note: See TracChangeset
for help on using the changeset viewer.