-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroTest.cpp
More file actions
39 lines (35 loc) · 962 Bytes
/
Copy pathmicroTest.cpp
File metadata and controls
39 lines (35 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Created by cwb on 2022/10/8.
//
#include <cmath>
#include <cstdarg>
#include <iostream>
// 宏定义可变参数
#define ADD_CODE_BLOCK_TEST(...) \
std::cout << "=========code before========" << std::endl; \
__VA_ARGS__ \
std::cout << "=========code end========" << std::endl
// 方法可变参数
double stddev(int count, ...)
{
double sum = 0;
double sum_sq = 0;
std::va_list args;
va_start(args, count);
for (int i = 0; i < count; ++i)
{
double num = va_arg(args, double);
sum += num;
sum_sq += num * num;
}
va_end(args);
return std::sqrt(sum_sq / count - (sum / count) * (sum / count));
}
void microTest()
{
ADD_CODE_BLOCK_TEST({
std::cout << "this is the insert code block!!!" << std::endl;
});
ADD_CODE_BLOCK_TEST();
std::cout << stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n';
}