The mathematical constants provided by the Python standard library Mathmath
Pi |
Mathematical constant Pi, the variable space belongs to the standard library math |
E |
The mathematical constant e,e is the natural constant, and the variable space belongs to the standard library math |
Function trigonometric functions commonly used in the math library
Name of function |
format |
function |
Sin Sin (x) The sine of the returnedxradian value Cos COS (x) x radians the cosine value of the returned Tan Tan (x) x radian the tangent value of the returned Asin ASIN (x) Returnedxby arcsine radians. ACOs ACOs (x) Returnedxby arccosine radians. Atan Atan (x) Returnedxby arctangent radian value. Atan2 atan2 (x, y) ReturnsXYthe inverse tangent value of the given and coordinate values. Degrees Degrees (x) degrees () Converts the radian x to an angle. Radians Radians (x) Returns one angle of the radian value. |
|
|
|
numeric functions
Name of function |
format |
function |
Exp |
EXP (x) |
Returns the exponent \ (e^x\)of X. |
Pow |
Pow (x, y) |
The POW () method returns the value of (x's y-square). |
sqrt |
sqrt (x) |
The sqrt () method returns the square root of the number x. |
Hypot |
Hypot (x, y) |
Hypot () returns the Euclidean normsqrt(x*x + y*y). |
Modf |
MODF(x) modf () method returns the X integer part and decimal part Fabs Fabs (x) fabs () method returns the absolute value of the number X Log Log (x) Returned by the log () methodx natural logarithm. Log10 LOG10 (x) The LOG10 () method returns the X logarithm of radix 10. Copysign Copysign (x, y) Returns the | x | value of the symbol as modulosign (y) Factorial Factorial (x) Calculationx! Fmod Fmod (x, y) x modulo y, the implementation is toC library return a more accurate floating-point number to the bottom Frexp Frexp (x) Returns a two-tuple, respectively, with the exponent part x mantissa part (m, e), x == m * 2 ** e Fsum Fsum (x) Returns a sum to be obtained floating point number. |
|
|
|
The other functions
X is not positive or negative infinity.
X is not a Nan (not a number),
Return x * (2**i). The opposite of Frexp ().
Integer part of Return x (truncated truncated) int (x)
Return e**x-1. When x is very small, it is more accurate.
Return log (1+X) based on E, x approximately 0 o'clock more accurate
(Hyperbola method) Hyperbolic functions
Return the inverse hyperbolic cosine of x.
Return the inverse hyperbolic sine of x.
Return the inverse hyperbolic tangent of x.
Return the hyperbolic cosine of X.
Return the hyperbolic sine of X.
Return the hyperbolic tangent of X.
(Special method) special functions
-
Math.erf (x)
-
MATH.ERFC (x)
-
Math.gamma (x)
-
Math.lgamma (x)
Python Standard library Cmath
Standard library Math lacks the operation of a complex number, and it is time to introduce another python built-in standard library, Cmath.
As follows:
>>> import math
>>> math.sqrt(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> import cmath
>>> cmath.sqrt(-1)
1j
You can see that the math.sqrt passed in a negative number, because the operation range in the real number will be error; Cmath.sqrt operation range in plural so the incoming parameter is-1 returns an imaginary number.
Cmath has most of the same functions as math, except that the operating range is within the complex number field, and there are still several functions worth remembering:
Equal to Math.atan2 (X.imag, x.real).
Equal to (ABS (x), phase (x)).
Equal to R * (Math.Cos (PHI) + Math.sin (PHI) *1j).
Return (X.IMAG+X.REAL*J)
Python STL Math&cmath