int main() { const int n {5}; double data[n] {1.2, 2.3, 3.4, 4.5, 5.6}; Stats stats; for (int i = 0; i < n; i++) stats.add(data[i]); std::cout << "average = " << stats.avg() << " for " << stats.n() << " data points" << std::endl; return 0; }
int main() { int i {0}; double x {0.0}; std::map<int,Stats> data; while (std::cin >> i >> x) { if (data.find(i) == data.end()) data.emplace(std::make_pair(i, Stats())); data[i].add(x); } for (const auto& values: data) { Stats stats = values.second; std::cout << values.first << " " << stats.avg() << " " << stats.min() << " " << stats.max() << std::endl; } return 0; }
void render(/*double currentTime*/) { currentTime += time_offset; static const GLfloat color[] = { 0.0f, 0.0f, 0.0f, 0.0f }; float r = 0.0f; float t = (float)currentTime; r = t + time_offset; glm::vec2 C( (sinf(r * 0.1f) + cosf(r * 0.53f)) * 2.5f, (cosf(r * 0.13f) + sinf(r * 0.21f)) * 0.5f ); i++; if((i % 100) == 0) { if(1) { int total = 0; int count = 0; int it_max = -1; int it_min = max_iterations + 1; int skip = 10; float a; float log_a_min = FLT_MAX; float log_a_max = FLT_MIN; stat_a.clear(); for(int px = 0; px < iscreen.x; px+=skip) { for(int py = 0; py < iscreen.y; py+=skip) { if(debug) { if((count%10)==0) { printf("%6s%6s%12s%12s%12s%12s%12s%6s%12s%12s%12s\n", "px", "py", "zoom", "f", "f", "x", "y", "it", "a", "log(a)", "a0"); }} int it = solve(glm::ivec2(px,py), C, a); count++; total += it; if(it > it_max) it_max = it; if(it < it_min) it_min = it; //printf("%f\n",a); stat_a.push(a); //printf("%f\n",a); if(isinf(a)) { stat_log_a.push((float)FLT_MAX_EXP); } else { stat_log_a.push(log(a)); } } } log_a_min = stat_log_a.min(); log_a_max = stat_log_a.max(); if(isinf(log_a_max)) { printf("inf log %f\n", (float)FLT_MAX_EXP); log_a_max = FLT_MAX_EXP; } printf("%8s%8s%8s%8s%8s%12s%12s%12s%12s%12s%12s\n", "count", "total", "avg", "it_min", "it_max", "a_min", "a_max", "log a_min", "log a_max", "avg log_a", "std log_a" ); printf("%8i%8i%8.2f%8i%8i%12.2e%12.2e%12.2e%12.2e%12.2e%12.2e\n", count, total, (float)total/(float)count, it_min, it_max, stat_a.min(), stat_a.max(), log_a_min, log_a_max, stat_log_a.avg(), stat_log_a.std()); } printf("%12s%12s\n","zoom","time"); printf("%12.2e%12.2f\n",zoom,currentTime); } float offset[2] = { x_offset, y_offset }; // rendering part glClearBufferfv(GL_COLOR, 0, color); glUseProgram(program); glUniform2fv(uniforms.C, 1, &C[0]); glUniform2fv(uniforms.offset, 1, offset); glUniform2fv(uniforms.screen, 1, &screen.x); glUniform1f(uniforms.zoom, zoom); glUniform1i(uniforms.iter, max_iterations); glUniform1i(uniforms.mode, mode); glUniform1f(uniforms.damp, damp); glUniform1f(uniforms.log_a_min, log_a_min); glUniform1f(uniforms.log_a_max, log_a_max); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glutSwapBuffers(); }