• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版de57843e3a4a1965b8b8c99ac68225ad99233d3a (tree)
时间2018-04-01 22:41:16
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Added new function break_fp().

更改概述

差异

--- a/include/MUtils/Global.h
+++ b/include/MUtils/Global.h
@@ -86,6 +86,15 @@ class QProcess;
8686 namespace MUtils
8787 {
8888 /**
89+ * \brief This struct containes the parts of a floating-point number
90+ */
91+ typedef struct
92+ {
93+ double intpart, fractpart;
94+ }
95+ fp_parts_t;
96+
97+ /**
8998 * \brief Rerieves the full path of the application's *Temp* folder.
9099 *
91100 * The application's *Temp* folder is a unique application-specific folder, intended to store any temporary files that the application may need. It will be created when this function is called for the first time (lazy initialization); subsequent calls are guaranteed to return the same path. Usually the application's *Temp* folder will be created as a sub-folder of the system's global *Temp* folder, as indicated by the `TMP` or `TEMP` environment variables. However, it may be created at a different place (e.g. in the users *Profile* directory), if those environment variables don't point to a usable directory. In any case, this function makes sure that the application's *Temp* folder exists for the whole lifetime of the application and that it is writable. When the application terminates normally, the application's *Temp* folder and all files or sub-directories thereof will be *removed* automatically!
@@ -329,6 +338,15 @@ namespace MUtils
329338 */
330339 MUTILS_API QStringList available_codepages(const bool &noAliases = true);
331340
341+ /**
342+ * \brief Break floating-point number into fractional and integral parts
343+ *
344+ * \param value The original floating-point value
345+ *
346+ * \return Returns a struct containing the fractional and integral parts
347+ */
348+ MUTILS_API fp_parts_t break_fp(const double value);
349+
332350 //Internal
333351 namespace Internal
334352 {
--- a/include/MUtils/Version.h
+++ b/include/MUtils/Version.h
@@ -68,7 +68,7 @@ namespace MUtils
6868 #endif
6969 #elif defined(_MSC_VER)
7070 #if (_MSC_VER == 1913)
71- #if((_MSC_FULL_VER >= 191326128) && (_MSC_FULL_VER <= 191326128))
71+ #if((_MSC_FULL_VER >= 191326128) && (_MSC_FULL_VER <= 191326129))
7272 "MSVC 2017.6";
7373 #else
7474 #error Compiler version is not supported yet!
--- a/src/Global.cpp
+++ b/src/Global.cpp
@@ -63,13 +63,12 @@
6363 //Per-thread init flag
6464 static QThreadStorage<bool> g_srand_flag;
6565
66+//32-Bit wrapper for qrand()
67+#define QRAND() ((static_cast<quint32>(qrand()) & 0xFFFF) | (static_cast<quint32>(qrand()) << 16U))
68+
6669 //Robert Jenkins' 96 bit Mix Function
67-static quint32 mix_function(const quint32 x, const quint32 y, const quint32 z)
70+static quint32 mix_function(quint32 a, quint32 b, quint32 c)
6871 {
69- quint32 a = x;
70- quint32 b = y;
71- quint32 c = z;
72-
7372 a=a-b; a=a-c; a=a^(c >> 13);
7473 b=b-c; b=b-a; b=b^(a << 8);
7574 c=c-a; c=c-b; c=c^(b >> 13);
@@ -86,24 +85,30 @@ static quint32 mix_function(const quint32 x, const quint32 y, const quint32 z)
8685 static void seed_rand(void)
8786 {
8887 QDateTime build(MUtils::Version::lib_build_date(), MUtils::Version::lib_build_time());
89- const quint32 seed = mix_function(MUtils::OS::process_id(), MUtils::OS::thread_id(), build.toMSecsSinceEpoch());
90- qsrand(mix_function(clock(), time(NULL), seed));
88+ const quint32 seed_0 = mix_function(MUtils::OS::process_id(), MUtils::OS::thread_id(), build.toMSecsSinceEpoch());
89+ qsrand(mix_function(clock(), time(NULL), seed_0));
9190 }
9291
9392 static quint32 rand_fallback(void)
9493 {
95- Q_ASSERT(RAND_MAX >= 0xFFF);
94+ Q_ASSERT(RAND_MAX >= 0x7FFF);
95+
9696 if (!(g_srand_flag.hasLocalData() && g_srand_flag.localData()))
9797 {
9898 seed_rand();
9999 g_srand_flag.setLocalData(true);
100100 }
101- quint32 rnd = 0x32288EA3;
102- for (size_t i = 0; i < 3; i++)
101+
102+ quint32 rnd_val = mix_function(0x32288EA3, clock(), time(NULL));
103+
104+ for (size_t i = 0; i < 42; i++)
103105 {
104- rnd = (rnd << 12) ^ qrand();
106+ rnd_val = mix_function(rnd_val, QRAND(), QRAND());
107+ rnd_val = mix_function(QRAND(), rnd_val, QRAND());
108+ rnd_val = mix_function(QRAND(), QRAND(), rnd_val);
105109 }
106- return rnd;
110+
111+ return rnd_val;
107112 }
108113
109114 quint32 MUtils::next_rand_u32(void)
@@ -802,6 +807,17 @@ QStringList MUtils::available_codepages(const bool &noAliases)
802807 }
803808
804809 ///////////////////////////////////////////////////////////////////////////////
810+// FP MATH SUPPORT
811+///////////////////////////////////////////////////////////////////////////////
812+
813+MUtils::fp_parts_t MUtils::break_fp(const double value)
814+{
815+ fp_parts_t result;
816+ result.fractpart = modf(value, &result.intpart);
817+ return result;
818+}
819+
820+///////////////////////////////////////////////////////////////////////////////
805821 // SELF-TEST
806822 ///////////////////////////////////////////////////////////////////////////////
807823
Show on old repository browser