本文整理汇总了C++中Stats::avg方法的典型用法代码示例。如果您正苦于以下问题:C++ Stats::avg方法的具体用法?C++ Stats::avg怎么用?C++ Stats::avg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stats
的用法示例。
在下文中一共展示了Stats::avg方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
示例2: main
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;
}
示例3: render
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());
}
//.........这里部分代码省略.........