#include #include #include "data.hpp" #include "toolbox.hpp" #define PBSTR "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" #define PBWIDTH 60 void printProgress(const float64_t& percentage) noexcept { const uint64_t val = static_cast(percentage * 100); const int32_t lpad = static_cast(percentage * PBWIDTH); const int32_t rpad = PBWIDTH - lpad; fprintf(stderr, "%3lu%% [%.*s%*s]\r", val, lpad, PBSTR, rpad, ""); fflush(stderr); } void clearProgress(void) noexcept { // Progress bar width + space before + num space + space after fprintf(stderr, "%*c\r", PBWIDTH + 1 + 3 + 3, ' '); } template void test(const uint64_t& N) noexcept { #if __DEBUG printf("DETERMINISTIC for N=%s of %s sized %s\n", thousand_sep(N).c_str(), typeid(T).name(), format_byte_size(sizeof(T)).c_str()); printf("Estimating memory footprint at : %s\n", format_byte_size(3 * N * sizeof(T)).c_str()); #endif T *a = new T[N], *b = new T[N], *c = new T[N]; T mean = static_cast(0.0); const size_t percent = N / 100; for(size_t i = 0; i < N; ++i){ if (i % percent == 0) printProgress(static_cast(i) / N); a[i] = static_cast(i < N>>1 ? 0.1 : 1.0); b[i] = static_cast(1.0); c[i] = a[i] * b[i]; mean += c[i]; } mean /= static_cast(N); clearProgress(); std::cout << mean << std::endl; delete[] a, delete[] b, delete[] c; } void test_float(void) noexcept { std::cout << std::setprecision(1<<8); const uint64_t N = static_cast(1)<<28; test(N); test(N); test(N); //printf("%.128af\n", static_cast(1) / 3); //std::cout << static_cast(1) / 3 << std::endl; //std::cout << std::hexfloat << static_cast(1) / 3 << std::endl; //printf("%.128Lf\n", static_cast(1) / 3); //printf("%.128lf\n", static_cast(1) / 3); //printf("%.128f\n", static_cast(1) / 3); }