数据类型
- unsigned char和uint8_t一样,都是8位,uint8_t更加健壮
math函数
-
std::atan和std::atan2
std::atan(x) 即tan(angle) = x 所求angle范围[-PI/2, PI/2] [-90°, 90°]
std::atan2(y, x) 即tan(angle)=y/x 所求angle范围[-PI, PI] [-180°, 180°]
math函数 | 描述 |
---|---|
std::fmod(x, y) | 计算x/y的浮点余数,如std::fmod(3.1, 2) = 1.1 对浮点数进行取模(求余),后一个数可以为0,返回NaN 。而%只用于整型的计算,后一个数不能为0 |
std::hypot(x, y) | 等同于 std::sqrt(xx + yy) |
std::floor(param) | 向下取整:不大于给定值的最近整数 4.5/4.2/4.8结果都为4 |
std::ceil(param) | 向上取整:不小于给定值的最近整数 4.5/4.2/4.8结果都为5 |
std::round(param) | 就近取整:即4舍5入取整 4.45为4 4.5/4.55为5 |
std::isfinite(param) | 若为正常有限数字,在-Infinity和Infinity之间返回true,infinity则返回false |
std::numeric_limits::epsilon() | 表示的是最小的大于0的浮点数,include<limits > |
FLT_MAX | 最大的正float浮点数 |
FLT_MIN | 最小的正float浮点数 |
boost相关 | 描述 |
boost::lexical_cast | 用于类型转换,使用的stringstream实现的数值类型转换 |
其他函数
std::to_string() //数值转string,需要包含头文件,C++11支持,CMakeLists.txt中要有add_compile_options(-std=c++11)
std::string a(“asdfasf”); //a.c_str(); 将C++的string转为C串,即char[]类型