OLD | NEW |
1 :mod:`math` --- Mathematical functions | 1 :mod:`math` --- Mathematical functions |
2 ====================================== | 2 ====================================== |
3 | 3 |
4 .. module:: math | 4 .. module:: math |
5 :synopsis: Mathematical functions (sin() etc.). | 5 :synopsis: Mathematical functions (sin() etc.). |
6 | 6 |
7 .. testsetup:: | 7 .. testsetup:: |
8 | 8 |
9 from math import fsum | 9 from math import fsum |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 noted otherwise, all return values are floats. | 24 noted otherwise, all return values are floats. |
25 | 25 |
26 | 26 |
27 Number-theoretic and representation functions | 27 Number-theoretic and representation functions |
28 --------------------------------------------- | 28 --------------------------------------------- |
29 | 29 |
30 .. function:: ceil(x) | 30 .. function:: ceil(x) |
31 | 31 |
32 Return the ceiling of *x*, the smallest integer greater than or equal to *x*. | 32 Return the ceiling of *x*, the smallest integer greater than or equal to *x*. |
33 If *x* is not a float, delegates to ``x.__ceil__()``, which should return an | 33 If *x* is not a float, delegates to ``x.__ceil__()``, which should return an |
34 :class:`Integral` value. | 34 :class:`~numbers.Integral` value. |
35 | 35 |
36 | 36 |
37 .. function:: copysign(x, y) | 37 .. function:: copysign(x, y) |
38 | 38 |
39 Return *x* with the sign of *y*. On a platform that supports | 39 Return *x* with the sign of *y*. On a platform that supports |
40 signed zeros, ``copysign(1.0, -0.0)`` returns *-1.0*. | 40 signed zeros, ``copysign(1.0, -0.0)`` returns *-1.0*. |
41 | 41 |
42 | 42 |
43 .. function:: fabs(x) | 43 .. function:: fabs(x) |
44 | 44 |
45 Return the absolute value of *x*. | 45 Return the absolute value of *x*. |
46 | 46 |
47 .. function:: factorial(x) | 47 .. function:: factorial(x) |
48 | 48 |
49 Return *x* factorial. Raises :exc:`ValueError` if *x* is not integral or | 49 Return *x* factorial. Raises :exc:`ValueError` if *x* is not integral or |
50 is negative. | 50 is negative. |
51 | 51 |
52 .. function:: floor(x) | 52 .. function:: floor(x) |
53 | 53 |
54 Return the floor of *x*, the largest integer less than or equal to *x*. | 54 Return the floor of *x*, the largest integer less than or equal to *x*. |
55 If *x* is not a float, delegates to ``x.__floor__()``, which should return an | 55 If *x* is not a float, delegates to ``x.__floor__()``, which should return an |
56 :class:`Integral` value. | 56 :class:`~numbers.Integral` value. |
57 | 57 |
58 | 58 |
59 .. function:: fmod(x, y) | 59 .. function:: fmod(x, y) |
60 | 60 |
61 Return ``fmod(x, y)``, as defined by the platform C library. Note that the | 61 Return ``fmod(x, y)``, as defined by the platform C library. Note that the |
62 Python expression ``x % y`` may not return the same result. The intent of th
e C | 62 Python expression ``x % y`` may not return the same result. The intent of th
e C |
63 standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite | 63 standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite |
64 precision) equal to ``x - n*y`` for some integer *n* such that the result has | 64 precision) equal to ``x - n*y`` for some integer *n* such that the result has |
65 the same sign as *x* and magnitude less than ``abs(y)``. Python's ``x % y`` | 65 the same sign as *x* and magnitude less than ``abs(y)``. Python's ``x % y`` |
66 returns a result with the sign of *y* instead, and may not be exactly computa
ble | 66 returns a result with the sign of *y* instead, and may not be exactly computa
ble |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 | 127 |
128 .. function:: modf(x) | 128 .. function:: modf(x) |
129 | 129 |
130 Return the fractional and integer parts of *x*. Both results carry the sign | 130 Return the fractional and integer parts of *x*. Both results carry the sign |
131 of *x* and are floats. | 131 of *x* and are floats. |
132 | 132 |
133 | 133 |
134 .. function:: trunc(x) | 134 .. function:: trunc(x) |
135 | 135 |
136 Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually | 136 Return the :class:`~numbers.Real` value *x* truncated to an :class:`~numbers.
Integral` (usually |
137 an integer). Delegates to ``x.__trunc__()``. | 137 an integer). Delegates to ``x.__trunc__()``. |
138 | 138 |
139 | 139 |
140 Note that :func:`frexp` and :func:`modf` have a different call/return pattern | 140 Note that :func:`frexp` and :func:`modf` have a different call/return pattern |
141 than their C equivalents: they take a single argument and return a pair of | 141 than their C equivalents: they take a single argument and return a pair of |
142 values, rather than returning their second return value through an 'output | 142 values, rather than returning their second return value through an 'output |
143 parameter' (there is no such thing in Python). | 143 parameter' (there is no such thing in Python). |
144 | 144 |
145 For the :func:`ceil`, :func:`floor`, and :func:`modf` functions, note that *all* | 145 For the :func:`ceil`, :func:`floor`, and :func:`modf` functions, note that *all* |
146 floating-point numbers of sufficiently large magnitude are exact integers. | 146 floating-point numbers of sufficiently large magnitude are exact integers. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 Note that Python makes no effort to distinguish signaling NaNs from | 399 Note that Python makes no effort to distinguish signaling NaNs from |
400 quiet NaNs, and behavior for signaling NaNs remains unspecified. | 400 quiet NaNs, and behavior for signaling NaNs remains unspecified. |
401 Typical behavior is to treat all NaNs as though they were quiet. | 401 Typical behavior is to treat all NaNs as though they were quiet. |
402 | 402 |
403 | 403 |
404 .. seealso:: | 404 .. seealso:: |
405 | 405 |
406 Module :mod:`cmath` | 406 Module :mod:`cmath` |
407 Complex number versions of many of these functions. | 407 Complex number versions of many of these functions. |
OLD | NEW |