站长之家官网入口,大连本地服务信息网,专门做家具的网站,网站建设制作多少钱cmath 是 C 标准库中的头文件#xff0c;它提供了一系列数学函数和常量#xff0c;用于执行各种数学计算。在 C 中#xff0c;cmath 头文件中定义的函数和常量都位于 std 命名空间中。
以下是 cmath 头文件中常用的一些函数和常量#xff1a;
常…cmath 是 C 标准库中的头文件它提供了一系列数学函数和常量用于执行各种数学计算。在 C 中cmath 头文件中定义的函数和常量都位于 std 命名空间中。
以下是 cmath 头文件中常用的一些函数和常量
常用数学函数 三角函数 sin, cos, tan求正弦、余弦、正切值。asin, acos, atan求反正弦、反余弦、反正切值。atan2求两个参数的反正切值。 双曲函数 sinh, cosh, tanh求双曲正弦、双曲余弦、双曲正切值。asinh, acosh, atanh求反双曲正弦、反双曲余弦、反双曲正切值。 指数和对数函数 exp, log, log10求指数、自然对数、常用对数。log2求以2为底的对数。pow求幂函数。 取整函数 ceil向上取整。floor向下取整。round四舍五入取整。 其他函数 sqrt求平方根。fabs求绝对值。fmod求浮点数取模。
常用数学常量
M_PIπ圆周率。M_Ee自然对数的底。
除了上述函数和常量cmath 还包含了其他一些数学函数和常量可根据具体需求进行查阅和使用。这些函数和常量能够帮助你在 C 中进行各种数学计算。
#include iostream
#include cmathint main() {// 计算平方根double x 16.0;double squareRoot std::sqrt(x);std::cout Square root of x is: squareRoot std::endl;// 计算正弦值double angle 45.0; // 角度double radians angle * M_PI / 180.0; // 将角度转换为弧度double sineValue std::sin(radians);std::cout Sine of angle degrees is: sineValue std::endl;// 计算自然对数double num 2.0;double naturalLog std::log(num);std::cout Natural logarithm of num is: naturalLog std::endl;// 计算指数double base 2.0;double exponent 3.0;double result std::pow(base, exponent);std::cout base raised to the power of exponent is: result std::endl;// 向上取整double y 4.3;double ceilValue std::ceil(y);std::cout Ceil value of y is: ceilValue std::endl;return 0;
}参考
https://en.cppreference.com/w/cpp/header/cmath