diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 247c36ee..160306c6 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -21,6 +21,12 @@ * along with this program. If not, see . */ +#ifdef _WIN32 +#define isnormal(x) (_fpclass(x) == _FPCLASS_NN || _fpclass(x) == _FPCLASS_PN) +#else +#include +#endif + #ifndef _WIN32 #if __cplusplus <= 199711L #include @@ -65,10 +71,15 @@ static int gettimeofday(struct timeval* tp, struct timezone* tzp) #include "workers/Hashrate.h" -inline const char* format(double h, char* buf, size_t size) +inline std::string format(const double value) { - snprintf(buf, size, "%03.1f", h); - return buf; + char buff[8]; + if(false == isnormal(value) && 0 != value) + { + return "n/a"; + } + snprintf(buff, sizeof(buff), "%03.1f", value); + return buff; } @@ -190,14 +201,11 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) void Hashrate::print() { - char num1[8]; - char num2[8]; - char num3[8]; - char num4[8]; - - LOG_INFO("speed 2.5s/60s/15m " << format(calc(ShortInterval), num1, - sizeof(num1)) << " " << format(calc(MediumInterval), num2, sizeof(num2)) << " " << format(calc(LargeInterval), - num3, sizeof(num3)) << " H/s max: " << format(m_highest, num4, sizeof(num4)) << " H/s"); + LOG_INFO("speed 2.5s/60s/15m " << + format(calc(ShortInterval)) << " " << + format(calc(MediumInterval)) << " " << + format(calc(LargeInterval)) << " H/s max: " << + format(m_highest) << " H/s"); } @@ -210,7 +218,7 @@ void Hashrate::stop() void Hashrate::updateHighest() { double highest = calc(ShortInterval); - if(0 != highest && highest > m_highest) + if(isnormal(highest) && highest > m_highest) { m_highest = highest; }