summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fmath.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/library%2Fmath.html')
-rw-r--r--devdocs/python~3.12/library%2Fmath.html219
1 files changed, 219 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fmath.html b/devdocs/python~3.12/library%2Fmath.html
new file mode 100644
index 00000000..ed500328
--- /dev/null
+++ b/devdocs/python~3.12/library%2Fmath.html
@@ -0,0 +1,219 @@
+ <span id="math-mathematical-functions"></span><h1>math — Mathematical functions</h1> <p>This module provides access to the mathematical functions defined by the C standard.</p> <p>These functions cannot be used with complex numbers; use the functions of the same name from the <a class="reference internal" href="cmath#module-cmath" title="cmath: Mathematical functions for complex numbers."><code>cmath</code></a> module if you require support for complex numbers. The distinction between functions which support complex numbers and those which don’t is made since most users do not want to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used as a parameter, so that the programmer can determine how and why it was generated in the first place.</p> <p>The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats.</p> <section id="number-theoretic-and-representation-functions"> <h2>Number-theoretic and representation functions</h2> <dl class="py function"> <dt class="sig sig-object py" id="math.ceil">
+<code>math.ceil(x)</code> </dt> <dd>
+<p>Return the ceiling of <em>x</em>, the smallest integer greater than or equal to <em>x</em>. If <em>x</em> is not a float, delegates to <a class="reference internal" href="../reference/datamodel#object.__ceil__" title="object.__ceil__"><code>x.__ceil__</code></a>, which should return an <a class="reference internal" href="numbers#numbers.Integral" title="numbers.Integral"><code>Integral</code></a> value.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.comb">
+<code>math.comb(n, k)</code> </dt> <dd>
+<p>Return the number of ways to choose <em>k</em> items from <em>n</em> items without repetition and without order.</p> <p>Evaluates to <code>n! / (k! * (n - k)!)</code> when <code>k &lt;= n</code> and evaluates to zero when <code>k &gt; n</code>.</p> <p>Also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of <code>(1 + x)ⁿ</code>.</p> <p>Raises <a class="reference internal" href="exceptions#TypeError" title="TypeError"><code>TypeError</code></a> if either of the arguments are not integers. Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if either of the arguments are negative.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.copysign">
+<code>math.copysign(x, y)</code> </dt> <dd>
+<p>Return a float with the magnitude (absolute value) of <em>x</em> but the sign of <em>y</em>. On platforms that support signed zeros, <code>copysign(1.0, -0.0)</code> returns <em>-1.0</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.fabs">
+<code>math.fabs(x)</code> </dt> <dd>
+<p>Return the absolute value of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.factorial">
+<code>math.factorial(n)</code> </dt> <dd>
+<p>Return <em>n</em> factorial as an integer. Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if <em>n</em> is not integral or is negative.</p> <div class="deprecated"> <p><span class="versionmodified deprecated">Deprecated since version 3.9: </span>Accepting floats with integral values (like <code>5.0</code>) is deprecated.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.floor">
+<code>math.floor(x)</code> </dt> <dd>
+<p>Return the floor of <em>x</em>, the largest integer less than or equal to <em>x</em>. If <em>x</em> is not a float, delegates to <a class="reference internal" href="../reference/datamodel#object.__floor__" title="object.__floor__"><code>x.__floor__</code></a>, which should return an <a class="reference internal" href="numbers#numbers.Integral" title="numbers.Integral"><code>Integral</code></a> value.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.fmod">
+<code>math.fmod(x, y)</code> </dt> <dd>
+<p>Return <code>fmod(x, y)</code>, as defined by the platform C library. Note that the Python expression <code>x % y</code> may not return the same result. The intent of the C standard is that <code>fmod(x, y)</code> be exactly (mathematically; to infinite precision) equal to <code>x - n*y</code> for some integer <em>n</em> such that the result has the same sign as <em>x</em> and magnitude less than <code>abs(y)</code>. Python’s <code>x % y</code> returns a result with the sign of <em>y</em> instead, and may not be exactly computable for float arguments. For example, <code>fmod(-1e-100, 1e100)</code> is <code>-1e-100</code>, but the result of Python’s <code>-1e-100 % 1e100</code> is <code>1e100-1e-100</code>, which cannot be represented exactly as a float, and rounds to the surprising <code>1e100</code>. For this reason, function <a class="reference internal" href="#math.fmod" title="math.fmod"><code>fmod()</code></a> is generally preferred when working with floats, while Python’s <code>x % y</code> is preferred when working with integers.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.frexp">
+<code>math.frexp(x)</code> </dt> <dd>
+<p>Return the mantissa and exponent of <em>x</em> as the pair <code>(m, e)</code>. <em>m</em> is a float and <em>e</em> is an integer such that <code>x == m * 2**e</code> exactly. If <em>x</em> is zero, returns <code>(0.0, 0)</code>, otherwise <code>0.5 &lt;= abs(m) &lt; 1</code>. This is used to “pick apart” the internal representation of a float in a portable way.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.fsum">
+<code>math.fsum(iterable)</code> </dt> <dd>
+<p>Return an accurate floating point sum of values in the iterable. Avoids loss of precision by tracking multiple intermediate partial sums.</p> <p>The algorithm’s accuracy depends on IEEE-754 arithmetic guarantees and the typical case where the rounding mode is half-even. On some non-Windows builds, the underlying C library uses extended precision addition and may occasionally double-round an intermediate sum causing it to be off in its least significant bit.</p> <p>For further discussion and two alternative approaches, see the <a class="reference external" href="https://code.activestate.com/recipes/393090/">ASPN cookbook recipes for accurate floating point summation</a>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.gcd">
+<code>math.gcd(*integers)</code> </dt> <dd>
+<p>Return the greatest common divisor of the specified integer arguments. If any of the arguments is nonzero, then the returned value is the largest positive integer that is a divisor of all arguments. If all arguments are zero, then the returned value is <code>0</code>. <code>gcd()</code> without arguments returns <code>0</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span>Added support for an arbitrary number of arguments. Formerly, only two arguments were supported.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.isclose">
+<code>math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)</code> </dt> <dd>
+<p>Return <code>True</code> if the values <em>a</em> and <em>b</em> are close to each other and <code>False</code> otherwise.</p> <p>Whether or not two values are considered close is determined according to given absolute and relative tolerances.</p> <p><em>rel_tol</em> is the relative tolerance – it is the maximum allowed difference between <em>a</em> and <em>b</em>, relative to the larger absolute value of <em>a</em> or <em>b</em>. For example, to set a tolerance of 5%, pass <code>rel_tol=0.05</code>. The default tolerance is <code>1e-09</code>, which assures that the two values are the same within about 9 decimal digits. <em>rel_tol</em> must be greater than zero.</p> <p><em>abs_tol</em> is the minimum absolute tolerance – useful for comparisons near zero. <em>abs_tol</em> must be at least zero.</p> <p>If no errors occur, the result will be: <code>abs(a-b) &lt;= max(rel_tol * max(abs(a), abs(b)), abs_tol)</code>.</p> <p>The IEEE 754 special values of <code>NaN</code>, <code>inf</code>, and <code>-inf</code> will be handled according to IEEE rules. Specifically, <code>NaN</code> is not considered close to any other value, including <code>NaN</code>. <code>inf</code> and <code>-inf</code> are only considered close to themselves.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0485/"><strong>PEP 485</strong></a> – A function for testing approximate equality</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.isfinite">
+<code>math.isfinite(x)</code> </dt> <dd>
+<p>Return <code>True</code> if <em>x</em> is neither an infinity nor a NaN, and <code>False</code> otherwise. (Note that <code>0.0</code> <em>is</em> considered finite.)</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.isinf">
+<code>math.isinf(x)</code> </dt> <dd>
+<p>Return <code>True</code> if <em>x</em> is a positive or negative infinity, and <code>False</code> otherwise.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.isnan">
+<code>math.isnan(x)</code> </dt> <dd>
+<p>Return <code>True</code> if <em>x</em> is a NaN (not a number), and <code>False</code> otherwise.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.isqrt">
+<code>math.isqrt(n)</code> </dt> <dd>
+<p>Return the integer square root of the nonnegative integer <em>n</em>. This is the floor of the exact square root of <em>n</em>, or equivalently the greatest integer <em>a</em> such that <em>a</em>² ≤ <em>n</em>.</p> <p>For some applications, it may be more convenient to have the least integer <em>a</em> such that <em>n</em> ≤ <em>a</em>², or in other words the ceiling of the exact square root of <em>n</em>. For positive <em>n</em>, this can be computed using <code>a = 1 + isqrt(n - 1)</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.lcm">
+<code>math.lcm(*integers)</code> </dt> <dd>
+<p>Return the least common multiple of the specified integer arguments. If all arguments are nonzero, then the returned value is the smallest positive integer that is a multiple of all arguments. If any of the arguments is zero, then the returned value is <code>0</code>. <code>lcm()</code> without arguments returns <code>1</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.ldexp">
+<code>math.ldexp(x, i)</code> </dt> <dd>
+<p>Return <code>x * (2**i)</code>. This is essentially the inverse of function <a class="reference internal" href="#math.frexp" title="math.frexp"><code>frexp()</code></a>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.modf">
+<code>math.modf(x)</code> </dt> <dd>
+<p>Return the fractional and integer parts of <em>x</em>. Both results carry the sign of <em>x</em> and are floats.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.nextafter">
+<code>math.nextafter(x, y, steps=1)</code> </dt> <dd>
+<p>Return the floating-point value <em>steps</em> steps after <em>x</em> towards <em>y</em>.</p> <p>If <em>x</em> is equal to <em>y</em>, return <em>y</em>, unless <em>steps</em> is zero.</p> <p>Examples:</p> <ul class="simple"> <li>
+<code>math.nextafter(x, math.inf)</code> goes up: towards positive infinity.</li> <li>
+<code>math.nextafter(x, -math.inf)</code> goes down: towards minus infinity.</li> <li>
+<code>math.nextafter(x, 0.0)</code> goes towards zero.</li> <li>
+<code>math.nextafter(x, math.copysign(math.inf, x))</code> goes away from zero.</li> </ul> <p>See also <a class="reference internal" href="#math.ulp" title="math.ulp"><code>math.ulp()</code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.12: </span>Added the <em>steps</em> argument.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.perm">
+<code>math.perm(n, k=None)</code> </dt> <dd>
+<p>Return the number of ways to choose <em>k</em> items from <em>n</em> items without repetition and with order.</p> <p>Evaluates to <code>n! / (n - k)!</code> when <code>k &lt;= n</code> and evaluates to zero when <code>k &gt; n</code>.</p> <p>If <em>k</em> is not specified or is None, then <em>k</em> defaults to <em>n</em> and the function returns <code>n!</code>.</p> <p>Raises <a class="reference internal" href="exceptions#TypeError" title="TypeError"><code>TypeError</code></a> if either of the arguments are not integers. Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if either of the arguments are negative.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.prod">
+<code>math.prod(iterable, *, start=1)</code> </dt> <dd>
+<p>Calculate the product of all the elements in the input <em>iterable</em>. The default <em>start</em> value for the product is <code>1</code>.</p> <p>When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.remainder">
+<code>math.remainder(x, y)</code> </dt> <dd>
+<p>Return the IEEE 754-style remainder of <em>x</em> with respect to <em>y</em>. For finite <em>x</em> and finite nonzero <em>y</em>, this is the difference <code>x - n*y</code>, where <code>n</code> is the closest integer to the exact value of the quotient <code>x /
+y</code>. If <code>x / y</code> is exactly halfway between two consecutive integers, the nearest <em>even</em> integer is used for <code>n</code>. The remainder <code>r = remainder(x,
+y)</code> thus always satisfies <code>abs(r) &lt;= 0.5 * abs(y)</code>.</p> <p>Special cases follow IEEE 754: in particular, <code>remainder(x, math.inf)</code> is <em>x</em> for any finite <em>x</em>, and <code>remainder(x, 0)</code> and <code>remainder(math.inf, x)</code> raise <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> for any non-NaN <em>x</em>. If the result of the remainder operation is zero, that zero will have the same sign as <em>x</em>.</p> <p>On platforms using IEEE 754 binary floating-point, the result of this operation is always exactly representable: no rounding error is introduced.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.sumprod">
+<code>math.sumprod(p, q)</code> </dt> <dd>
+<p>Return the sum of products of values from two iterables <em>p</em> and <em>q</em>.</p> <p>Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if the inputs do not have the same length.</p> <p>Roughly equivalent to:</p> <pre data-language="python">sum(itertools.starmap(operator.mul, zip(p, q, strict=True)))
+</pre> <p>For float and mixed int/float inputs, the intermediate products and sums are computed with extended precision.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.trunc">
+<code>math.trunc(x)</code> </dt> <dd>
+<p>Return <em>x</em> with the fractional part removed, leaving the integer part. This rounds toward 0: <code>trunc()</code> is equivalent to <a class="reference internal" href="#math.floor" title="math.floor"><code>floor()</code></a> for positive <em>x</em>, and equivalent to <a class="reference internal" href="#math.ceil" title="math.ceil"><code>ceil()</code></a> for negative <em>x</em>. If <em>x</em> is not a float, delegates to <a class="reference internal" href="../reference/datamodel#object.__trunc__" title="object.__trunc__"><code>x.__trunc__</code></a>, which should return an <a class="reference internal" href="numbers#numbers.Integral" title="numbers.Integral"><code>Integral</code></a> value.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.ulp">
+<code>math.ulp(x)</code> </dt> <dd>
+<p>Return the value of the least significant bit of the float <em>x</em>:</p> <ul class="simple"> <li>If <em>x</em> is a NaN (not a number), return <em>x</em>.</li> <li>If <em>x</em> is negative, return <code>ulp(-x)</code>.</li> <li>If <em>x</em> is a positive infinity, return <em>x</em>.</li> <li>If <em>x</em> is equal to zero, return the smallest positive <em>denormalized</em> representable float (smaller than the minimum positive <em>normalized</em> float, <a class="reference internal" href="sys#sys.float_info" title="sys.float_info"><code>sys.float_info.min</code></a>).</li> <li>If <em>x</em> is equal to the largest positive representable float, return the value of the least significant bit of <em>x</em>, such that the first float smaller than <em>x</em> is <code>x - ulp(x)</code>.</li> <li>Otherwise (<em>x</em> is a positive finite number), return the value of the least significant bit of <em>x</em>, such that the first float bigger than <em>x</em> is <code>x + ulp(x)</code>.</li> </ul> <p>ULP stands for “Unit in the Last Place”.</p> <p>See also <a class="reference internal" href="#math.nextafter" title="math.nextafter"><code>math.nextafter()</code></a> and <a class="reference internal" href="sys#sys.float_info" title="sys.float_info"><code>sys.float_info.epsilon</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <p>Note that <a class="reference internal" href="#math.frexp" title="math.frexp"><code>frexp()</code></a> and <a class="reference internal" href="#math.modf" title="math.modf"><code>modf()</code></a> have a different call/return pattern than their C equivalents: they take a single argument and return a pair of values, rather than returning their second return value through an ‘output parameter’ (there is no such thing in Python).</p> <p>For the <a class="reference internal" href="#math.ceil" title="math.ceil"><code>ceil()</code></a>, <a class="reference internal" href="#math.floor" title="math.floor"><code>floor()</code></a>, and <a class="reference internal" href="#math.modf" title="math.modf"><code>modf()</code></a> functions, note that <em>all</em> floating-point numbers of sufficiently large magnitude are exact integers. Python floats typically carry no more than 53 bits of precision (the same as the platform C double type), in which case any float <em>x</em> with <code>abs(x) &gt;= 2**52</code> necessarily has no fractional bits.</p> </section> <section id="power-and-logarithmic-functions"> <h2>Power and logarithmic functions</h2> <dl class="py function"> <dt class="sig sig-object py" id="math.cbrt">
+<code>math.cbrt(x)</code> </dt> <dd>
+<p>Return the cube root of <em>x</em>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.exp">
+<code>math.exp(x)</code> </dt> <dd>
+<p>Return <em>e</em> raised to the power <em>x</em>, where <em>e</em> = 2.718281… is the base of natural logarithms. This is usually more accurate than <code>math.e ** x</code> or <code>pow(math.e, x)</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.exp2">
+<code>math.exp2(x)</code> </dt> <dd>
+<p>Return <em>2</em> raised to the power <em>x</em>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.expm1">
+<code>math.expm1(x)</code> </dt> <dd>
+<p>Return <em>e</em> raised to the power <em>x</em>, minus 1. Here <em>e</em> is the base of natural logarithms. For small floats <em>x</em>, the subtraction in <code>exp(x) - 1</code> can result in a <a class="reference external" href="https://en.wikipedia.org/wiki/Loss_of_significance">significant loss of precision</a>; the <a class="reference internal" href="#math.expm1" title="math.expm1"><code>expm1()</code></a> function provides a way to compute this quantity to full precision:</p> <pre data-language="python">&gt;&gt;&gt; from math import exp, expm1
+&gt;&gt;&gt; exp(1e-5) - 1 # gives result accurate to 11 places
+1.0000050000069649e-05
+&gt;&gt;&gt; expm1(1e-5) # result accurate to full precision
+1.0000050000166668e-05
+</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.log">
+<code>math.log(x[, base])</code> </dt> <dd>
+<p>With one argument, return the natural logarithm of <em>x</em> (to base <em>e</em>).</p> <p>With two arguments, return the logarithm of <em>x</em> to the given <em>base</em>, calculated as <code>log(x)/log(base)</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.log1p">
+<code>math.log1p(x)</code> </dt> <dd>
+<p>Return the natural logarithm of <em>1+x</em> (base <em>e</em>). The result is calculated in a way which is accurate for <em>x</em> near zero.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.log2">
+<code>math.log2(x)</code> </dt> <dd>
+<p>Return the base-2 logarithm of <em>x</em>. This is usually more accurate than <code>log(x, 2)</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="stdtypes#int.bit_length" title="int.bit_length"><code>int.bit_length()</code></a> returns the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.log10">
+<code>math.log10(x)</code> </dt> <dd>
+<p>Return the base-10 logarithm of <em>x</em>. This is usually more accurate than <code>log(x, 10)</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.pow">
+<code>math.pow(x, y)</code> </dt> <dd>
+<p>Return <code>x</code> raised to the power <code>y</code>. Exceptional cases follow the IEEE 754 standard as far as possible. In particular, <code>pow(1.0, x)</code> and <code>pow(x, 0.0)</code> always return <code>1.0</code>, even when <code>x</code> is a zero or a NaN. If both <code>x</code> and <code>y</code> are finite, <code>x</code> is negative, and <code>y</code> is not an integer then <code>pow(x, y)</code> is undefined, and raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a>.</p> <p>Unlike the built-in <code>**</code> operator, <a class="reference internal" href="#math.pow" title="math.pow"><code>math.pow()</code></a> converts both its arguments to type <a class="reference internal" href="functions#float" title="float"><code>float</code></a>. Use <code>**</code> or the built-in <a class="reference internal" href="functions#pow" title="pow"><code>pow()</code></a> function for computing exact integer powers.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>The special cases <code>pow(0.0, -inf)</code> and <code>pow(-0.0, -inf)</code> were changed to return <code>inf</code> instead of raising <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a>, for consistency with IEEE 754.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.sqrt">
+<code>math.sqrt(x)</code> </dt> <dd>
+<p>Return the square root of <em>x</em>.</p> </dd>
+</dl> </section> <section id="trigonometric-functions"> <h2>Trigonometric functions</h2> <dl class="py function"> <dt class="sig sig-object py" id="math.acos">
+<code>math.acos(x)</code> </dt> <dd>
+<p>Return the arc cosine of <em>x</em>, in radians. The result is between <code>0</code> and <code>pi</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.asin">
+<code>math.asin(x)</code> </dt> <dd>
+<p>Return the arc sine of <em>x</em>, in radians. The result is between <code>-pi/2</code> and <code>pi/2</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.atan">
+<code>math.atan(x)</code> </dt> <dd>
+<p>Return the arc tangent of <em>x</em>, in radians. The result is between <code>-pi/2</code> and <code>pi/2</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.atan2">
+<code>math.atan2(y, x)</code> </dt> <dd>
+<p>Return <code>atan(y / x)</code>, in radians. The result is between <code>-pi</code> and <code>pi</code>. The vector in the plane from the origin to point <code>(x, y)</code> makes this angle with the positive X axis. The point of <a class="reference internal" href="#math.atan2" title="math.atan2"><code>atan2()</code></a> is that the signs of both inputs are known to it, so it can compute the correct quadrant for the angle. For example, <code>atan(1)</code> and <code>atan2(1, 1)</code> are both <code>pi/4</code>, but <code>atan2(-1,
+-1)</code> is <code>-3*pi/4</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.cos">
+<code>math.cos(x)</code> </dt> <dd>
+<p>Return the cosine of <em>x</em> radians.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.dist">
+<code>math.dist(p, q)</code> </dt> <dd>
+<p>Return the Euclidean distance between two points <em>p</em> and <em>q</em>, each given as a sequence (or iterable) of coordinates. The two points must have the same dimension.</p> <p>Roughly equivalent to:</p> <pre data-language="python">sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
+</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.hypot">
+<code>math.hypot(*coordinates)</code> </dt> <dd>
+<p>Return the Euclidean norm, <code>sqrt(sum(x**2 for x in coordinates))</code>. This is the length of the vector from the origin to the point given by the coordinates.</p> <p>For a two dimensional point <code>(x, y)</code>, this is equivalent to computing the hypotenuse of a right triangle using the Pythagorean theorem, <code>sqrt(x*x + y*y)</code>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>Added support for n-dimensional points. Formerly, only the two dimensional case was supported.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>Improved the algorithm’s accuracy so that the maximum error is under 1 ulp (unit in the last place). More typically, the result is almost always correctly rounded to within 1/2 ulp.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.sin">
+<code>math.sin(x)</code> </dt> <dd>
+<p>Return the sine of <em>x</em> radians.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.tan">
+<code>math.tan(x)</code> </dt> <dd>
+<p>Return the tangent of <em>x</em> radians.</p> </dd>
+</dl> </section> <section id="angular-conversion"> <h2>Angular conversion</h2> <dl class="py function"> <dt class="sig sig-object py" id="math.degrees">
+<code>math.degrees(x)</code> </dt> <dd>
+<p>Convert angle <em>x</em> from radians to degrees.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.radians">
+<code>math.radians(x)</code> </dt> <dd>
+<p>Convert angle <em>x</em> from degrees to radians.</p> </dd>
+</dl> </section> <section id="hyperbolic-functions"> <h2>Hyperbolic functions</h2> <p><a class="reference external" href="https://en.wikipedia.org/wiki/Hyperbolic_functions">Hyperbolic functions</a> are analogs of trigonometric functions that are based on hyperbolas instead of circles.</p> <dl class="py function"> <dt class="sig sig-object py" id="math.acosh">
+<code>math.acosh(x)</code> </dt> <dd>
+<p>Return the inverse hyperbolic cosine of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.asinh">
+<code>math.asinh(x)</code> </dt> <dd>
+<p>Return the inverse hyperbolic sine of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.atanh">
+<code>math.atanh(x)</code> </dt> <dd>
+<p>Return the inverse hyperbolic tangent of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.cosh">
+<code>math.cosh(x)</code> </dt> <dd>
+<p>Return the hyperbolic cosine of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.sinh">
+<code>math.sinh(x)</code> </dt> <dd>
+<p>Return the hyperbolic sine of <em>x</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.tanh">
+<code>math.tanh(x)</code> </dt> <dd>
+<p>Return the hyperbolic tangent of <em>x</em>.</p> </dd>
+</dl> </section> <section id="special-functions"> <h2>Special functions</h2> <dl class="py function"> <dt class="sig sig-object py" id="math.erf">
+<code>math.erf(x)</code> </dt> <dd>
+<p>Return the <a class="reference external" href="https://en.wikipedia.org/wiki/Error_function">error function</a> at <em>x</em>.</p> <p>The <a class="reference internal" href="#math.erf" title="math.erf"><code>erf()</code></a> function can be used to compute traditional statistical functions such as the <a class="reference external" href="https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_functions">cumulative standard normal distribution</a>:</p> <pre data-language="python">def phi(x):
+ 'Cumulative distribution function for the standard normal distribution'
+ return (1.0 + erf(x / sqrt(2.0))) / 2.0
+</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.erfc">
+<code>math.erfc(x)</code> </dt> <dd>
+<p>Return the complementary error function at <em>x</em>. The <a class="reference external" href="https://en.wikipedia.org/wiki/Error_function">complementary error function</a> is defined as <code>1.0 - erf(x)</code>. It is used for large values of <em>x</em> where a subtraction from one would cause a <a class="reference external" href="https://en.wikipedia.org/wiki/Loss_of_significance">loss of significance</a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.gamma">
+<code>math.gamma(x)</code> </dt> <dd>
+<p>Return the <a class="reference external" href="https://en.wikipedia.org/wiki/Gamma_function">Gamma function</a> at <em>x</em>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="math.lgamma">
+<code>math.lgamma(x)</code> </dt> <dd>
+<p>Return the natural logarithm of the absolute value of the Gamma function at <em>x</em>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> </section> <section id="constants"> <h2>Constants</h2> <dl class="py data"> <dt class="sig sig-object py" id="math.pi">
+<code>math.pi</code> </dt> <dd>
+<p>The mathematical constant <em>π</em> = 3.141592…, to available precision.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="math.e">
+<code>math.e</code> </dt> <dd>
+<p>The mathematical constant <em>e</em> = 2.718281…, to available precision.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="math.tau">
+<code>math.tau</code> </dt> <dd>
+<p>The mathematical constant <em>τ</em> = 6.283185…, to available precision. Tau is a circle constant equal to 2<em>π</em>, the ratio of a circle’s circumference to its radius. To learn more about Tau, check out Vi Hart’s video <a class="reference external" href="https://www.youtube.com/watch?v=jG7vhMMXagQ">Pi is (still) Wrong</a>, and start celebrating <a class="reference external" href="https://tauday.com/">Tau day</a> by eating twice as much pie!</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.6.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="math.inf">
+<code>math.inf</code> </dt> <dd>
+<p>A floating-point positive infinity. (For negative infinity, use <code>-math.inf</code>.) Equivalent to the output of <code>float('inf')</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="math.nan">
+<code>math.nan</code> </dt> <dd>
+<p>A floating-point “not a number” (NaN) value. Equivalent to the output of <code>float('nan')</code>. Due to the requirements of the <a class="reference external" href="https://en.wikipedia.org/wiki/IEEE_754">IEEE-754 standard</a>, <code>math.nan</code> and <code>float('nan')</code> are not considered to equal to any other numeric value, including themselves. To check whether a number is a NaN, use the <a class="reference internal" href="#math.isnan" title="math.isnan"><code>isnan()</code></a> function to test for NaNs instead of <code>is</code> or <code>==</code>. Example:</p> <pre data-language="python">&gt;&gt;&gt; import math
+&gt;&gt;&gt; math.nan == math.nan
+False
+&gt;&gt;&gt; float('nan') == float('nan')
+False
+&gt;&gt;&gt; math.isnan(math.nan)
+True
+&gt;&gt;&gt; math.isnan(float('nan'))
+True
+</pre> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>It is now always available.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> <div class="impl-detail compound"> <p class="compound-first"><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#module-math" title="math: Mathematical functions (sin() etc.)."><code>math</code></a> module consists mostly of thin wrappers around the platform C math library functions. Behavior in exceptional cases follows Annex F of the C99 standard where appropriate. The current implementation will raise <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> for invalid operations like <code>sqrt(-1.0)</code> or <code>log(0.0)</code> (where C99 Annex F recommends signaling invalid operation or divide-by-zero), and <a class="reference internal" href="exceptions#OverflowError" title="OverflowError"><code>OverflowError</code></a> for results that overflow (for example, <code>exp(1000.0)</code>). A NaN will not be returned from any of the functions above unless one or more of the input arguments was a NaN; in that case, most functions will return a NaN, but (again following C99 Annex F) there are some exceptions to this rule, for example <code>pow(float('nan'), 0.0)</code> or <code>hypot(float('nan'), float('inf'))</code>.</p> <p class="compound-last">Note that Python makes no effort to distinguish signaling NaNs from quiet NaNs, and behavior for signaling NaNs remains unspecified. Typical behavior is to treat all NaNs as though they were quiet.</p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt>
+<code>Module</code> <a class="reference internal" href="cmath#module-cmath" title="cmath: Mathematical functions for complex numbers."><code>cmath</code></a>
+</dt>
+<dd>
+<p>Complex number versions of many of these functions.</p> </dd> </dl> </div> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/math.html" class="_attribution-link">https://docs.python.org/3.12/library/math.html</a>
+ </p>
+</div>