Spaces:
Running
on
Zero
Running
on
Zero
<html><head><title>Python: module math</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
</head><body bgcolor="#f0f0f8"> | |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> | |
<tr bgcolor="#7799ee"> | |
<td valign=bottom> <br> | |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>math</strong></big></big></font></td | |
><td align=right valign=bottom | |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/lib/python3.10/lib-dynload/math.cpython-310-x86_64-linux-gnu.so">/usr/local/lib/python3.10/lib-dynload/math.cpython-310-x86_64-linux-gnu.so</a><br><a href="https://docs.python.org/3.10/library/math.html">Module Reference</a></font></td></tr></table> | |
<p><tt>This module provides access to the mathematical functions<br> | |
defined by the C standard.</tt></p> | |
<p> | |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |
<tr bgcolor="#eeaa77"> | |
<td colspan=3 valign=bottom> <br> | |
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> | |
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> | |
<td width="100%"><dl><dt><a name="-acos"><strong>acos</strong></a>(x, /)</dt><dd><tt>Return the arc cosine (measured in radians) of x.<br> | |
<br> | |
The result is between 0 and pi.</tt></dd></dl> | |
<dl><dt><a name="-acosh"><strong>acosh</strong></a>(x, /)</dt><dd><tt>Return the inverse hyperbolic cosine of x.</tt></dd></dl> | |
<dl><dt><a name="-asin"><strong>asin</strong></a>(x, /)</dt><dd><tt>Return the arc sine (measured in radians) of x.<br> | |
<br> | |
The result is between -pi/2 and pi/2.</tt></dd></dl> | |
<dl><dt><a name="-asinh"><strong>asinh</strong></a>(x, /)</dt><dd><tt>Return the inverse hyperbolic sine of x.</tt></dd></dl> | |
<dl><dt><a name="-atan"><strong>atan</strong></a>(x, /)</dt><dd><tt>Return the arc tangent (measured in radians) of x.<br> | |
<br> | |
The result is between -pi/2 and pi/2.</tt></dd></dl> | |
<dl><dt><a name="-atan2"><strong>atan2</strong></a>(y, x, /)</dt><dd><tt>Return the arc tangent (measured in radians) of y/x.<br> | |
<br> | |
Unlike <a href="#-atan">atan</a>(y/x), the signs of both x and y are considered.</tt></dd></dl> | |
<dl><dt><a name="-atanh"><strong>atanh</strong></a>(x, /)</dt><dd><tt>Return the inverse hyperbolic tangent of x.</tt></dd></dl> | |
<dl><dt><a name="-ceil"><strong>ceil</strong></a>(x, /)</dt><dd><tt>Return the ceiling of x as an Integral.<br> | |
<br> | |
This is the smallest integer >= x.</tt></dd></dl> | |
<dl><dt><a name="-comb"><strong>comb</strong></a>(n, k, /)</dt><dd><tt>Number of ways to choose k items from n items without repetition and without order.<br> | |
<br> | |
Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates<br> | |
to zero when k > n.<br> | |
<br> | |
Also called the binomial coefficient because it is equivalent<br> | |
to the coefficient of k-th term in polynomial expansion of the<br> | |
expression (1 + x)**n.<br> | |
<br> | |
Raises TypeError if either of the arguments are not integers.<br> | |
Raises ValueError if either of the arguments are negative.</tt></dd></dl> | |
<dl><dt><a name="-copysign"><strong>copysign</strong></a>(x, y, /)</dt><dd><tt>Return a float with the magnitude (absolute value) of x but the sign of y.<br> | |
<br> | |
On platforms that support signed zeros, <a href="#-copysign">copysign</a>(1.0, -0.0)<br> | |
returns -1.0.</tt></dd></dl> | |
<dl><dt><a name="-cos"><strong>cos</strong></a>(x, /)</dt><dd><tt>Return the cosine of x (measured in radians).</tt></dd></dl> | |
<dl><dt><a name="-cosh"><strong>cosh</strong></a>(x, /)</dt><dd><tt>Return the hyperbolic cosine of x.</tt></dd></dl> | |
<dl><dt><a name="-degrees"><strong>degrees</strong></a>(x, /)</dt><dd><tt>Convert angle x from radians to degrees.</tt></dd></dl> | |
<dl><dt><a name="-dist"><strong>dist</strong></a>(p, q, /)</dt><dd><tt>Return the Euclidean distance between two points p and q.<br> | |
<br> | |
The points should be specified as sequences (or iterables) of<br> | |
coordinates. Both inputs must have the same dimension.<br> | |
<br> | |
Roughly equivalent to:<br> | |
<a href="#-sqrt">sqrt</a>(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))</tt></dd></dl> | |
<dl><dt><a name="-erf"><strong>erf</strong></a>(x, /)</dt><dd><tt>Error function at x.</tt></dd></dl> | |
<dl><dt><a name="-erfc"><strong>erfc</strong></a>(x, /)</dt><dd><tt>Complementary error function at x.</tt></dd></dl> | |
<dl><dt><a name="-exp"><strong>exp</strong></a>(x, /)</dt><dd><tt>Return e raised to the power of x.</tt></dd></dl> | |
<dl><dt><a name="-expm1"><strong>expm1</strong></a>(x, /)</dt><dd><tt>Return <a href="#-exp">exp</a>(x)-1.<br> | |
<br> | |
This function avoids the loss of precision involved in the direct evaluation of <a href="#-exp">exp</a>(x)-1 for small x.</tt></dd></dl> | |
<dl><dt><a name="-fabs"><strong>fabs</strong></a>(x, /)</dt><dd><tt>Return the absolute value of the float x.</tt></dd></dl> | |
<dl><dt><a name="-factorial"><strong>factorial</strong></a>(x, /)</dt><dd><tt>Find x!.<br> | |
<br> | |
Raise a ValueError if x is negative or non-integral.</tt></dd></dl> | |
<dl><dt><a name="-floor"><strong>floor</strong></a>(x, /)</dt><dd><tt>Return the floor of x as an Integral.<br> | |
<br> | |
This is the largest integer <= x.</tt></dd></dl> | |
<dl><dt><a name="-fmod"><strong>fmod</strong></a>(x, y, /)</dt><dd><tt>Return <a href="#-fmod">fmod</a>(x, y), according to platform C.<br> | |
<br> | |
x % y may differ.</tt></dd></dl> | |
<dl><dt><a name="-frexp"><strong>frexp</strong></a>(x, /)</dt><dd><tt>Return the mantissa and exponent of x, as pair (m, e).<br> | |
<br> | |
m is a float and e is an int, such that x = m * 2.**e.<br> | |
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.</tt></dd></dl> | |
<dl><dt><a name="-fsum"><strong>fsum</strong></a>(seq, /)</dt><dd><tt>Return an accurate floating point sum of values in the iterable seq.<br> | |
<br> | |
Assumes IEEE-754 floating point arithmetic.</tt></dd></dl> | |
<dl><dt><a name="-gamma"><strong>gamma</strong></a>(x, /)</dt><dd><tt>Gamma function at x.</tt></dd></dl> | |
<dl><dt><a name="-gcd"><strong>gcd</strong></a>(*integers)</dt><dd><tt>Greatest Common Divisor.</tt></dd></dl> | |
<dl><dt><a name="-hypot"><strong>hypot</strong></a>(...)</dt><dd><tt><a href="#-hypot">hypot</a>(*coordinates) -> value<br> | |
<br> | |
Multidimensional Euclidean distance from the origin to a point.<br> | |
<br> | |
Roughly equivalent to:<br> | |
<a href="#-sqrt">sqrt</a>(sum(x**2 for x in coordinates))<br> | |
<br> | |
For a two dimensional point (x, y), gives the hypotenuse<br> | |
using the Pythagorean theorem: <a href="#-sqrt">sqrt</a>(x*x + y*y).<br> | |
<br> | |
For example, the hypotenuse of a 3/4/5 right triangle is:<br> | |
<br> | |
>>> <a href="#-hypot">hypot</a>(3.0, 4.0)<br> | |
5.0</tt></dd></dl> | |
<dl><dt><a name="-isclose"><strong>isclose</strong></a>(a, b, *, rel_tol=1e-09, abs_tol=0.0)</dt><dd><tt>Determine whether two floating point numbers are close in value.<br> | |
<br> | |
rel_tol<br> | |
maximum difference for being considered "close", relative to the<br> | |
magnitude of the input values<br> | |
abs_tol<br> | |
maximum difference for being considered "close", regardless of the<br> | |
magnitude of the input values<br> | |
<br> | |
Return True if a is close in value to b, and False otherwise.<br> | |
<br> | |
For the values to be considered close, the difference between them<br> | |
must be smaller than at least one of the tolerances.<br> | |
<br> | |
-inf, inf and NaN behave similarly to the IEEE 754 Standard. That<br> | |
is, NaN is not close to anything, even itself. inf and -inf are<br> | |
only close to themselves.</tt></dd></dl> | |
<dl><dt><a name="-isfinite"><strong>isfinite</strong></a>(x, /)</dt><dd><tt>Return True if x is neither an infinity nor a NaN, and False otherwise.</tt></dd></dl> | |
<dl><dt><a name="-isinf"><strong>isinf</strong></a>(x, /)</dt><dd><tt>Return True if x is a positive or negative infinity, and False otherwise.</tt></dd></dl> | |
<dl><dt><a name="-isnan"><strong>isnan</strong></a>(x, /)</dt><dd><tt>Return True if x is a NaN (not a number), and False otherwise.</tt></dd></dl> | |
<dl><dt><a name="-isqrt"><strong>isqrt</strong></a>(n, /)</dt><dd><tt>Return the integer part of the square root of the input.</tt></dd></dl> | |
<dl><dt><a name="-lcm"><strong>lcm</strong></a>(*integers)</dt><dd><tt>Least Common Multiple.</tt></dd></dl> | |
<dl><dt><a name="-ldexp"><strong>ldexp</strong></a>(x, i, /)</dt><dd><tt>Return x * (2**i).<br> | |
<br> | |
This is essentially the inverse of <a href="#-frexp">frexp</a>().</tt></dd></dl> | |
<dl><dt><a name="-lgamma"><strong>lgamma</strong></a>(x, /)</dt><dd><tt>Natural logarithm of absolute value of Gamma function at x.</tt></dd></dl> | |
<dl><dt><a name="-log"><strong>log</strong></a>(...)</dt><dd><tt><a href="#-log">log</a>(x, [base=math.e])<br> | |
Return the logarithm of x to the given base.<br> | |
<br> | |
If the base not specified, returns the natural logarithm (base e) of x.</tt></dd></dl> | |
<dl><dt><a name="-log10"><strong>log10</strong></a>(x, /)</dt><dd><tt>Return the base 10 logarithm of x.</tt></dd></dl> | |
<dl><dt><a name="-log1p"><strong>log1p</strong></a>(x, /)</dt><dd><tt>Return the natural logarithm of 1+x (base e).<br> | |
<br> | |
The result is computed in a way which is accurate for x near zero.</tt></dd></dl> | |
<dl><dt><a name="-log2"><strong>log2</strong></a>(x, /)</dt><dd><tt>Return the base 2 logarithm of x.</tt></dd></dl> | |
<dl><dt><a name="-modf"><strong>modf</strong></a>(x, /)</dt><dd><tt>Return the fractional and integer parts of x.<br> | |
<br> | |
Both results carry the sign of x and are floats.</tt></dd></dl> | |
<dl><dt><a name="-nextafter"><strong>nextafter</strong></a>(x, y, /)</dt><dd><tt>Return the next floating-point value after x towards y.</tt></dd></dl> | |
<dl><dt><a name="-perm"><strong>perm</strong></a>(n, k=None, /)</dt><dd><tt>Number of ways to choose k items from n items without repetition and with order.<br> | |
<br> | |
Evaluates to n! / (n - k)! when k <= n and evaluates<br> | |
to zero when k > n.<br> | |
<br> | |
If k is not specified or is None, then k defaults to n<br> | |
and the function returns n!.<br> | |
<br> | |
Raises TypeError if either of the arguments are not integers.<br> | |
Raises ValueError if either of the arguments are negative.</tt></dd></dl> | |
<dl><dt><a name="-pow"><strong>pow</strong></a>(x, y, /)</dt><dd><tt>Return x**y (x to the power of y).</tt></dd></dl> | |
<dl><dt><a name="-prod"><strong>prod</strong></a>(iterable, /, *, start=1)</dt><dd><tt>Calculate the product of all the elements in the input iterable.<br> | |
<br> | |
The default start value for the product is 1.<br> | |
<br> | |
When the iterable is empty, return the start value. This function is<br> | |
intended specifically for use with numeric values and may reject<br> | |
non-numeric types.</tt></dd></dl> | |
<dl><dt><a name="-radians"><strong>radians</strong></a>(x, /)</dt><dd><tt>Convert angle x from degrees to radians.</tt></dd></dl> | |
<dl><dt><a name="-remainder"><strong>remainder</strong></a>(x, y, /)</dt><dd><tt>Difference between x and the closest integer multiple of y.<br> | |
<br> | |
Return x - n*y where n*y is the closest integer multiple of y.<br> | |
In the case where x is exactly halfway between two multiples of<br> | |
y, the nearest even value of n is used. The result is always exact.</tt></dd></dl> | |
<dl><dt><a name="-sin"><strong>sin</strong></a>(x, /)</dt><dd><tt>Return the sine of x (measured in radians).</tt></dd></dl> | |
<dl><dt><a name="-sinh"><strong>sinh</strong></a>(x, /)</dt><dd><tt>Return the hyperbolic sine of x.</tt></dd></dl> | |
<dl><dt><a name="-sqrt"><strong>sqrt</strong></a>(x, /)</dt><dd><tt>Return the square root of x.</tt></dd></dl> | |
<dl><dt><a name="-tan"><strong>tan</strong></a>(x, /)</dt><dd><tt>Return the tangent of x (measured in radians).</tt></dd></dl> | |
<dl><dt><a name="-tanh"><strong>tanh</strong></a>(x, /)</dt><dd><tt>Return the hyperbolic tangent of x.</tt></dd></dl> | |
<dl><dt><a name="-trunc"><strong>trunc</strong></a>(x, /)</dt><dd><tt>Truncates the Real x to the nearest Integral toward 0.<br> | |
<br> | |
Uses the __trunc__ magic method.</tt></dd></dl> | |
<dl><dt><a name="-ulp"><strong>ulp</strong></a>(x, /)</dt><dd><tt>Return the value of the least significant bit of the float x.</tt></dd></dl> | |
</td></tr></table><p> | |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |
<tr bgcolor="#55aa55"> | |
<td colspan=3 valign=bottom> <br> | |
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> | |
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> | |
<td width="100%"><strong>e</strong> = 2.718281828459045<br> | |
<strong>inf</strong> = inf<br> | |
<strong>nan</strong> = nan<br> | |
<strong>pi</strong> = 3.141592653589793<br> | |
<strong>tau</strong> = 6.283185307179586</td></tr></table> | |
</body></html> |