math
— 数学函数
¶
此模块提供对 C 标准定义数学函数的访问。
这些函数无法用于复数;使用的同名函数来自
cmath
模块若要求支持复数。支持复数和那些不支持复数的函数之间的区别,是由于大多数用户不想学习理解复数要求的那么多数学知识。接收异常而不是复杂结果允许更早地检测用作参数的意外复数,所以,程序员可以确定它最初是如何生成的及为什么生成。
此模块提供下列函数。除另有明确说明外,所有返回值是浮点数。
|
Number-theoretic functions |
|
|
Number of ways to choose k items from n items without repetition and without order |
|
|
n factorial |
|
|
Greatest common divisor of the integer arguments |
|
|
Integer square root of a nonnegative integer n |
|
|
Least common multiple of the integer arguments |
|
|
Number of ways to choose k items from n items without repetition and with order |
|
|
Floating point arithmetic |
|
|
Ceiling of x ,最小整数 >= x |
|
|
Absolute value of x |
|
|
Floor of x , the largest integer less than or equal to x |
|
|
Fused multiply-add operation:
|
|
|
Remainder of division
|
|
|
Fractional and integer parts of x |
|
|
Remainder of x with respect to y |
|
|
Integer part of x |
|
|
Floating point manipulation functions |
|
|
Magnitude (absolute value) of x with the sign of y |
|
|
Mantissa and exponent of x |
|
|
Check if the values a and b are close to each other |
|
|
Check if x is neither an infinity nor a NaN |
|
|
Check if x is a positive or negative infinity |
|
|
Check if x is a NaN (not a number) |
|
|
|
|
|
Floating-point value steps steps after x towards y |
|
|
Value of the least significant bit of x |
|
|
Power, exponential and logarithmic functions |
|
|
Cube root of x |
|
|
e 自乘幂 x |
|
|
2 自乘幂 x |
|
|
e 自乘幂 x , minus 1 |
|
|
Logarithm of x to the given base ( e by default) |
|
|
Natural logarithm of 1+x (基 e ) |
|
|
Base-2 logarithm of x |
|
|
Base-10 logarithm of x |
|
|
x 自乘幂 y |
|
|
Square root of x |
|
|
Summation and product functions |
|
|
Euclidean distance between two points p and q given as an iterable of coordinates |
|
|
Sum of values in the input iterable |
|
|
Euclidean norm of an iterable of coordinates |
|
|
Product of elements in the input iterable 采用 start 值 |
|
|
Sum of products from two iterables p and q |
|
|
角度转换 |
|
|
转换角度 x from radians to degrees |
|
|
转换角度 x from degrees to radians |
|
|
三角函数 |
|
|
Arc cosine of x |
|
|
Arc sine of x |
|
|
Arc tangent of x |
|
|
|
|
|
Cosine of x |
|
|
Sine of x |
|
|
Tangent of x |
|
|
双曲函数 |
|
|
Inverse hyperbolic cosine of x |
|
|
Inverse hyperbolic sine of x |
|
|
Inverse hyperbolic tangent of x |
|
|
Hyperbolic cosine of x |
|
|
Hyperbolic sine of x |
|
|
Hyperbolic tangent of x |
|
|
特殊函数 |
|
|
Error function at x |
|
|
伽玛函数 at x |
|
|
Natural logarithm of the absolute value of the 伽玛函数 at x |
|
|
常量 |
|
|
π = 3.141592… |
|
|
e = 2.718281… |
|
|
τ = 2 π = 6.283185… |
|
|
Positive infinity |
|
|
“Not a number” (NaN) |
|
Number-theoretic functions ¶
- math. comb ( n , k ) ¶
-
Return the number of ways to choose k items from n items without repetition and without order.
评估为
n! / (k! * (n - k)!)当k <= n和评估为 0 当k > n.Also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of
(1 + x)ⁿ.引发
TypeError若任一自变量不是整数。引发ValueError若任一自变量为负。Added in version 3.8.