C++官网参考链接:https://cplusplus.com/reference/cmath/
头文件
<cmath> (math.h)
C数字库
头文件<cmath>声明了一组函数来计算常见的数学操作和转换:
函数
三角函数
Compute cosine (function) (计算余弦(函数))
Compute sine (function) (计算正弦(函数))
Compute tangent (function) (计算正切(函数))
Compute arc cosine (function) (计算反余弦(函数))
Compute arc sine (function) (计算反正弦(函数))
Compute arc tangent (function) (计算反正切(函数))
Compute arc tangent with two parameters (function) (使用两个形参计算反正切(函数))
双曲函数
Compute hyperbolic cosine (function) (计算双曲余弦(函数))
Compute hyperbolic sine (function) (计算双曲正弦(函数))
Compute hyperbolic tangent (function) (计算双曲正切(函数))
Compute area hyperbolic cosine (function) (计算反双曲余弦(函数))
Compute area hyperbolic sine (function) (计算反双曲正弦(函数))
Compute area hyperbolic tangent (function) (计算反双曲正切(函数))
指数函数和对数函数
Compute exponential function (function) (计算指数函数(函数))
Get significand and exponent (function) (获取有效值和指数(函数))
Generate value from significand and exponent (function) (从有效值和指数生成值(函数))
Compute natural logarithm (function) (计算自然对数(函数))
Compute common logarithm (function) (计算普通对数(函数))
Break into fractional and integral parts (function) (分解为小数部分和整数部分(函数))
Compute binary exponential function (function) (计算以2为底的指数函数(函数))
Compute exponential minus one (function) (计算以e为底数的指数减1(函数))
Integer binary logarithm (function) (整数以浮点基数为底的对数(函数))
Compute logarithm plus one (function) (计算真数加1的和的自然对数(函数))
Compute binary logarithm (function) (计算以2为底数的对数(函数))
Compute floating-point base logarithm (function) (计算以浮点基数为底的对数(函数))
Scale significand using floating-point base exponent (function) (使用以浮点基数为底的指数缩放有效值(函数))
Scale significand using floating-point base exponent (long) (function) (使用以浮点基数为底的指数的指数(long)缩放有效值(函数))
幂函数
Raise to power (function) (求幂(函数))
Compute square root (function) (计算平方根(函数))
Compute cubic root (function) (计算立方根(函数))
Compute hypotenuse (function) (计算斜边(函数))
误差和伽马函数
Compute error function (function) (计算误差函数(函数))
Compute complementary error function (function) (计算互补误差函数(函数))
Compute gamma function (function) (计算伽马函数(函数))
Compute log-gamma function (function) (计算对数伽马函数(函数))
舍入和余数函数
Round up value (function) (向上舍入取值(函数))
Round down value (function) (向下舍入取值(函数))
Compute remainder of division (function) (计算除法的余数(函数))
Truncate value (function) (截断取值(函数))
Round to nearest (function) (向最近舍入(函数))
Round to nearest and cast to long integer (function) (向最近舍入和转换为long整数(函数))
Round to nearest and cast to long long integer (function) (向最近舍入和转换为long long整数(函数))
Round to integral value (function) (向整数值舍入(函数))
Round and cast to long integer (function) (舍入和转换为long整数(函数))
Round and cast to long long integer (function) (舍入和转换为long long整数(函数))
Round to nearby integral value (function) (舍入到附近的整数值(函数))
Compute remainder (IEC 60559) (function) (计算余数(IEC 60559)(函数))
Compute remainder and quotient (function) (计算余数和商(函数))
浮点操作函数
Copy sign (function) (复制符号(函数))
Generate quiet NaN (function) (生成安静NaN(函数))
Next representable value (function) (下一个可表示的值(函数))
Next representable value toward precise value (function) (下一个可表示的指向精确值的值(函数))
最小值,最大值,差数函数
Positive difference (function) (正的差数(函数))
Maximum value (function) (最大值(函数))
Minimum value (function) (最小值(函数))
其他函数
Compute absolute value (function) (计算绝对值(函数))
Compute absolute value (function) (计算绝对值(函数))
Multiply-add (function) (乘-加(函数))
宏/函数
它们在C中以宏的形式实现,在C++中以函数的形式实现:
分类宏/函数
Classify floating-point value (macro/function) (分类浮点值(宏/函数))
Is finite value (macro) (有限值(宏))
Is infinity (macro/function) (无限值(宏/函数))
Is Not-A-Number (macro/function) (不是一个数(宏/函数))
Is normal (macro/function) (正常值(宏/函数))
Sign bit (macro/function) (符号位(宏/函数))
比较宏/函数
Is greater (macro) (大于(宏))
Is greater or equal (macro) (大于或者等于(宏))
Is less (macro) (小于(宏))
Is less or equal (macro) (小于或等于(宏))
Is less or greater (macro) (大于或小于(宏))
Is unordered (macro) (无序(宏))
宏常量
Error handling (macro) (错误处理(宏))
Infinity (constant) (无限(常量))
Not-A-Number (constant) (不是一个数(常量))
Huge value (constant) (巨大的值(常量))
Huge float value (巨大的float值)
Huge long double value (constant) (巨大的long double值(常量))
这个头文件还定义了以下宏常量(从C99/C++ 11开始):
macro | type | description |
---|---|---|
MATH_ERRNO MATH_ERREXCEPT | int | Bitmask value with the possible values math_errhandling can take. (math_errhandling可以接受的可能值的位掩码值。) |
FP_FAST_FMA FP_FAST_FMAF FP_FAST_FMAL | int | Each, if defined, identifies for which type fma is at least as efficient as (每一个,如果定义,确定哪种类型的fma至少与x*y+z一样有效。) |
FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO | int | The possible values returned by fpclassify. (fpclassify返回的可能值。) |
FP_ILOGB0 FP_ILOGBNAN | int | Special values the ilogb function may return. (ilogb函数可能返回的特殊值。) |
类型
Floating-point type (type) (浮点类型(类型))
Floating-point type (type) (浮点类型(类型))