C++ Reference: Standard C++ Library reference: C Library: cmath
C++官网参考链接:https://cplusplus.com/reference/cmath/
头文件
<cmath> (math.h)
C数字库
头文件<cmath>声明了一组函数来计算常见的数学操作和转换:
函数
三角函数
cos
Compute cosine (function) (计算余弦(函数))
sin
Compute sine (function) (计算正弦(函数))
tan
Compute tangent (function) (计算正切(函数))
acos
Compute arc cosine (function) (计算反余弦(函数))
asin
Compute arc sine (function) (计算反正弦(函数))
atan
Compute arc tangent (function) (计算反正切(函数))
atan2
Compute arc tangent with two parameters (function) (使用两个参数计算反正切(函数))
双曲函数
cosh
Compute hyperbolic cosine (function) (计算双曲余弦(函数))
sinh
Compute hyperbolic sine (function) (计算双曲正弦(函数))
tanh
Compute hyperbolic tangent (function) (计算双曲正切(函数))
acosh
Compute area hyperbolic cosine (function) (计算反双曲余弦(函数))
asinh
Compute area hyperbolic sine (function) (计算反双曲正弦(函数))
atanh
Compute area hyperbolic tangent (function) (计算反双曲正切(函数))
指数函数和对数函数
exp
Compute exponential function (function) (计算指数函数(函数))
frexp
Get significand and exponent (function) (获取有效值和指数(函数))
ldexp
Generate value from significand and exponent (function) (从有效值和指数(函数)生成值)
log
Compute natural logarithm (function) (计算自然对数(函数))
log10
Compute common logarithm (function) (计算公对数(函数))
modf
Break into fractional and integral parts (function) (分解为小数部分和整数部分(函数))
exp2
Compute binary exponential function (function) (计算二元指数函数(函数))
expm1
Compute exponential minus one (function) (计算指数减1(函数))
ilogb
Integer binary logarithm (function) (整数二进制对数(函数))
log1p
Compute logarithm plus one (function) (计算对数加1(函数))
log2
Compute binary logarithm (function) (计算二元对数(函数))
logb
Compute floating-point base logarithm (function) (计算浮点基对数(函数))
scalbn
Scale significand using floating-point base exponent (function) (使用浮点基指数(函数)进行缩放有效值)
scalbln
Scale significand using floating-point base exponent (long) (function) (使用浮点基指数(long)(函数)进行缩放有效值)
幂函数
pow
Raise to power (function) (求幂(函数))
sqrt
Compute square root (function) (计算平方根(函数))
cbrt
Compute cubic root (function) (计算立方根(函数))
hypot
Compute hypotenuse (function) (计算斜边(函数))
误差和伽马函数
erf
Compute error function (function) (计算误差函数(函数))
erfc
Compute complementary error function (function) (计算互补误差函数(函数))
tgamma
Compute gamma function (function) (计算伽马函数(函数))
lgamma
Compute log-gamma function (function) (计算对数伽玛函数(函数))
舍入和余数函数
ceil
Round up value (function) (向上取值(函数))
floor
Round down value (function) (向下取值(函数))
fmod
Compute remainder of division (function) (计算除法的余数(函数))
trunc
Truncate value (function) (截断值(函数))
round
Round to nearest (function) (向最近舍入(函数))
lround
Round to nearest and cast to long integer (function) (向最近舍入和转换为long整型(函数))
llround
Round to nearest and cast to long long integer (function) (向最近舍入和转换为long long整型(函数))
rint
Round to integral value (function) (向整数值舍入(函数))
lrint
Round and cast to long integer (function) (舍入和转换为long整型(函数))
llrint
Round and cast to long long integer (function) (舍入和转换为long long整型(函数))
nearbyint
Round to nearby integral value (function) (舍入到附近的整数值(函数))
remainder
Compute remainder (IEC 60559) (function) (计算余数(IEC 60559)(函数))
remquo
Compute remainder and quotient (function) (计算余数和商(函数))
浮点操作函数
copysign
Copy sign (function) (复制符号(函数))
nan
Generate quiet NaN (function) (生成安静NaN(函数))
nextafter
Next representable value (function) (下一个可表示的值(函数))
nexttoward
Next representable value toward precise value (function) (下一个可表示指向精确值的值(函数))
最小值,最大值,差分函数
fdim
Positive difference (function) (正差分(函数))
fmax
Maximum value (function) (最大值(函数))
fmin
Minimum value (function) (最小值(函数))
其他函数
fabs
Compute absolute value (function) (计算绝对值(函数))
abs
Compute absolute value (function) (计算绝对值(函数))
fma
Multiply-add (function)
宏/函数
它们在C中以宏的形式实现,在C++中以函数的形式实现:
分类宏/函数
fpclassify
Classify floating-point value (macro/function) (分类浮点值(宏/函数))
isfinite
Is finite value (macro) (是无限值(宏))
isinf
Is infinity (macro/function) (是无穷(宏/函数))
isnan
Is Not-A-Number (macro/function) (不是一个数(宏/函数))
isnormal
Is normal (macro/function) (是正常的(宏/函数))
signbit
Sign bit (macro/function) (符号位(宏/函数))
比较宏/函数
isgreater
Is greater (macro) (更大(宏))
isgreaterequal
Is greater or equal (macro) (大于或者等于(宏))
isless
Is less (macro) (更小(宏))
islessequal
Is less or equal (macro) (小于或等于(宏))
islessgreater
Is less or greater (macro) (更大或更小(宏))
isunordered
Is unordered (macro) (无序(宏))
宏常量
math_errhandling
Error handling (macro) (错误处理(宏))
INFINITY
Infinity (constant) (无穷(常量))
NAN
Not-A-Number (constant) (不是一个数(常量))
HUGE_VAL
Huge value (constant) (巨大的值(常量))
HUGE_VALF
Huge float value (巨大的浮点值)
HUGE_VALL
Huge long double value (constant) (巨大的长双精度值(常量))
这个头文件还定义了以下宏常量(从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 x*y+z .(每一个,如果定义,确定哪种类型的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函数可能返回的特殊值。) |
类型
double_t
Floating-point type (type) (浮点类型(类型))
float_t
Floating-point type (type) (浮点类型(类型))