Mercurial > cpython-lru_cache-weakref
annotate Doc/library/math.rst @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 9800ab236c09 |
| children | e157ceb54a43 |
| rev | line source |
|---|---|
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
1 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
2 :mod:`math` --- Mathematical functions |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
3 ====================================== |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
4 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
5 .. module:: math |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
6 :synopsis: Mathematical functions (sin() etc.). |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
7 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
8 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
9 This module is always available. It provides access to the mathematical |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
10 functions defined by the C standard. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
11 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
12 These functions cannot be used with complex numbers; use the functions of the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
13 same name from the :mod:`cmath` module if you require support for complex |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
14 numbers. The distinction between functions which support complex numbers and |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
15 those which don't is made since most users do not want to learn quite as much |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 mathematics as required to understand complex numbers. Receiving an exception |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 instead of a complex result allows earlier detection of the unexpected complex |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 number used as a parameter, so that the programmer can determine how and why it |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
19 was generated in the first place. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
20 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
21 The following functions are provided by this module. Except when explicitly |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
22 noted otherwise, all return values are floats. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
23 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 |
| 50235 | 25 Number-theoretic and representation functions |
| 26 --------------------------------------------- | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
27 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 .. function:: ceil(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
29 |
|
44488
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44480
diff
changeset
|
30 Return the ceiling of *x* as a float, the smallest integer value greater than or |
|
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44480
diff
changeset
|
31 equal to *x*. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
32 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
33 |
|
44440
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
34 .. function:: copysign(x, y) |
|
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
35 |
|
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
36 Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE |
|
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
37 754 float, ``copysign(1, -0.0)`` returns *-1.0*. |
|
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
38 |
| 44480 | 39 .. versionadded:: 2.6 |
|
44440
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
40 |
|
6208b17d0dbe
Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents:
44437
diff
changeset
|
41 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
42 .. function:: fabs(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
43 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
44 Return the absolute value of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
46 |
|
47529
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47215
diff
changeset
|
47 .. function:: factorial(x) |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47215
diff
changeset
|
48 |
| 47758 | 49 Return *x* factorial. Raises :exc:`ValueError` if *x* is not integral or |
|
47529
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47215
diff
changeset
|
50 is negative. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
51 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
52 .. versionadded:: 2.6 |
|
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
53 |
|
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
54 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
55 .. function:: floor(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
56 |
|
44488
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44480
diff
changeset
|
57 Return the floor of *x* as a float, the largest integer value less than or equal |
|
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44480
diff
changeset
|
58 to *x*. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
59 |
|
44495
0c0aebc6656f
Remove with_statement future imports from 2.6 docs.
Georg Brandl <georg@python.org>
parents:
44488
diff
changeset
|
60 .. versionchanged:: 2.6 |
|
0c0aebc6656f
Remove with_statement future imports from 2.6 docs.
Georg Brandl <georg@python.org>
parents:
44488
diff
changeset
|
61 Added :meth:`__floor__` delegation. |
|
0c0aebc6656f
Remove with_statement future imports from 2.6 docs.
Georg Brandl <georg@python.org>
parents:
44488
diff
changeset
|
62 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
63 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
64 .. function:: fmod(x, y) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
65 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
66 Return ``fmod(x, y)``, as defined by the platform C library. Note that the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
67 Python expression ``x % y`` may not return the same result. The intent of the C |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
68 standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
69 precision) equal to ``x - n*y`` for some integer *n* such that the result has |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
70 the same sign as *x* and magnitude less than ``abs(y)``. Python's ``x % y`` |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
71 returns a result with the sign of *y* instead, and may not be exactly computable |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
72 for float arguments. For example, ``fmod(-1e-100, 1e100)`` is ``-1e-100``, but |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
73 the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, which cannot be |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
74 represented exactly as a float, and rounds to the surprising ``1e100``. For |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
75 this reason, function :func:`fmod` is generally preferred when working with |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
76 floats, while Python's ``x % y`` is preferred when working with integers. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
77 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
78 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
79 .. function:: frexp(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
80 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
81 Return the mantissa and exponent of *x* as the pair ``(m, e)``. *m* is a float |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
82 and *e* is an integer such that ``x == m * 2**e`` exactly. If *x* is zero, |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
83 returns ``(0.0, 0)``, otherwise ``0.5 <= abs(m) < 1``. This is used to "pick |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
84 apart" the internal representation of a float in a portable way. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
85 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
86 |
|
48101
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
87 .. function:: fsum(iterable) |
|
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
88 |
|
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
89 Return an accurate floating point sum of values in the iterable. Avoids |
|
51728
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
90 loss of precision by tracking multiple intermediate partial sums:: |
|
48101
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
91 |
|
51728
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
92 >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
93 0.99999999999999989 |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
94 >>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
95 1.0 |
|
48105
67d177aab8a7
Add note about problems with math.fsum on x86 hardware.
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
96 |
|
51728
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
97 The algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
98 typical case where the rounding mode is half-even. On some non-Windows |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
99 builds, the underlying C library uses extended precision addition and may |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
100 occasionally double-round an intermediate sum causing it to be off in its |
|
559e4fc31c8a
Add an example for math.fsum() and elaborate on the accurary note.
Raymond Hettinger <python@rcn.com>
parents:
50508
diff
changeset
|
101 least significant bit. |
|
48105
67d177aab8a7
Add note about problems with math.fsum on x86 hardware.
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
102 |
|
51732
9800ab236c09
Add links to helpful external resources.
Raymond Hettinger <python@rcn.com>
parents:
51728
diff
changeset
|
103 For further discussion and two alternative approaches, see the `ASPN cookbook |
|
9800ab236c09
Add links to helpful external resources.
Raymond Hettinger <python@rcn.com>
parents:
51728
diff
changeset
|
104 recipes for accurate floating point summation |
|
9800ab236c09
Add links to helpful external resources.
Raymond Hettinger <python@rcn.com>
parents:
51728
diff
changeset
|
105 <http://code.activestate.com/recipes/393090/>`_\. |
|
9800ab236c09
Add links to helpful external resources.
Raymond Hettinger <python@rcn.com>
parents:
51728
diff
changeset
|
106 |
|
48101
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
107 .. versionadded:: 2.6 |
|
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
108 |
|
8d05dda735f8
Rename math.sum to math.fsum
Mark Dickinson <dickinsm@gmail.com>
parents:
47759
diff
changeset
|
109 |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
110 .. function:: isinf(x) |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
111 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
112 Checks if the float *x* is positive or negative infinite. |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
113 |
| 44480 | 114 .. versionadded:: 2.6 |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
115 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
116 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
117 .. function:: isnan(x) |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
118 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
119 Checks if the float *x* is a NaN (not a number). NaNs are part of the |
|
50508
c52177f36852
Remove trailing whitespace.
Georg Brandl <georg@python.org>
parents:
50243
diff
changeset
|
120 IEEE 754 standards. Operation like but not limited to ``inf * 0``, |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
121 ``inf / inf`` or any operation involving a NaN, e.g. ``nan * 1``, return |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
122 a NaN. |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
123 |
| 44480 | 124 .. versionadded:: 2.6 |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
125 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
126 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
127 .. function:: ldexp(x, i) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
128 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
129 Return ``x * (2**i)``. This is essentially the inverse of function |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
130 :func:`frexp`. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
131 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
132 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
133 .. function:: modf(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
134 |
|
50234
9fb2a23eac43
copy sentence from docstring
Benjamin Peterson <benjamin@python.org>
parents:
48904
diff
changeset
|
135 Return the fractional and integer parts of *x*. Both results carry the sign |
|
50243
589edf615adb
remove redundant sentence
Benjamin Peterson <benjamin@python.org>
parents:
50235
diff
changeset
|
136 of *x* and are floats. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
137 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
138 |
|
45079
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
139 .. function:: trunc(x) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
140 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
141 Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
142 a long integer). Delegates to ``x.__trunc__()``. |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
143 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
144 .. versionadded:: 2.6 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44495
diff
changeset
|
145 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
146 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
147 Note that :func:`frexp` and :func:`modf` have a different call/return pattern |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
148 than their C equivalents: they take a single argument and return a pair of |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
149 values, rather than returning their second return value through an 'output |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
150 parameter' (there is no such thing in Python). |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
151 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
152 For the :func:`ceil`, :func:`floor`, and :func:`modf` functions, note that *all* |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
153 floating-point numbers of sufficiently large magnitude are exact integers. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
154 Python floats typically carry no more than 53 bits of precision (the same as the |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
155 platform C double type), in which case any float *x* with ``abs(x) >= 2**52`` |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
156 necessarily has no fractional bits. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
157 |
| 50235 | 158 |
| 159 Power and logarithmic functions | |
| 160 ------------------------------- | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
161 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
162 .. function:: exp(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
163 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
164 Return ``e**x``. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
165 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
166 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
167 .. function:: log(x[, base]) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
168 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
169 Return the logarithm of *x* to the given *base*. If the *base* is not specified, |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
170 return the natural logarithm of *x* (that is, the logarithm to base *e*). |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
171 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
172 .. versionchanged:: 2.3 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
173 *base* argument added. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
174 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
175 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
176 .. function:: log1p(x) |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
177 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
178 Return the natural logarithm of *1+x* (base *e*). The |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
179 result is calculated in a way which is accurate for *x* near zero. |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
180 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
181 .. versionadded:: 2.6 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
182 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
183 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
184 .. function:: log10(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
185 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
186 Return the base-10 logarithm of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
187 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
188 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
189 .. function:: pow(x, y) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
190 |
|
46495
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
191 Return ``x`` raised to the power ``y``. Exceptional cases follow |
|
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
192 Annex 'F' of the C99 standard as far as possible. In particular, |
|
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
193 ``pow(1.0, x)`` and ``pow(x, 0.0)`` always return ``1.0``, even |
|
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
194 when ``x`` is a zero or a NaN. If both ``x`` and ``y`` are finite, |
|
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
195 ``x`` is negative, and ``y`` is not an integer then ``pow(x, y)`` |
|
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
196 is undefined, and raises :exc:`ValueError`. |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
197 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
198 .. versionchanged:: 2.6 |
|
46495
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
199 The outcome of ``1**nan`` and ``nan**0`` was undefined. |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
200 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
201 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
202 .. function:: sqrt(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
203 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
204 Return the square root of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
205 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
206 |
| 50235 | 207 Trigonometric functions |
| 208 ----------------------- | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
209 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
210 .. function:: acos(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
211 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
212 Return the arc cosine of *x*, in radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
213 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
214 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
215 .. function:: asin(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
216 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
217 Return the arc sine of *x*, in radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
218 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
219 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
220 .. function:: atan(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
221 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
222 Return the arc tangent of *x*, in radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
223 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
224 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
225 .. function:: atan2(y, x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
226 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
227 Return ``atan(y / x)``, in radians. The result is between ``-pi`` and ``pi``. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
228 The vector in the plane from the origin to point ``(x, y)`` makes this angle |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
229 with the positive X axis. The point of :func:`atan2` is that the signs of both |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
230 inputs are known to it, so it can compute the correct quadrant for the angle. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
231 For example, ``atan(1``) and ``atan2(1, 1)`` are both ``pi/4``, but ``atan2(-1, |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
232 -1)`` is ``-3*pi/4``. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
233 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
234 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
235 .. function:: cos(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
236 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
237 Return the cosine of *x* radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
238 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
239 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
240 .. function:: hypot(x, y) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
241 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
242 Return the Euclidean norm, ``sqrt(x*x + y*y)``. This is the length of the vector |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
243 from the origin to point ``(x, y)``. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
244 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
245 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
246 .. function:: sin(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
247 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
248 Return the sine of *x* radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
249 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
250 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
251 .. function:: tan(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
252 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
253 Return the tangent of *x* radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
254 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
255 |
| 50235 | 256 Angular conversion |
| 257 ------------------ | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
258 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
259 .. function:: degrees(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
260 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
261 Converts angle *x* from radians to degrees. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
262 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
263 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
264 .. function:: radians(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
265 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
266 Converts angle *x* from degrees to radians. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
267 |
|
47759
b4d823483421
Add versionadded tags to new math functions.
Georg Brandl <georg@python.org>
parents:
47758
diff
changeset
|
268 |
| 50235 | 269 Hyperbolic functions |
| 270 -------------------- | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
271 |
|
46496
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
272 .. function:: acosh(x) |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
273 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
274 Return the inverse hyperbolic cosine of *x*. |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
275 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
276 .. versionadded:: 2.6 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
277 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
278 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
279 .. function:: asinh(x) |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
280 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
281 Return the inverse hyperbolic sine of *x*. |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
282 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
283 .. versionadded:: 2.6 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
284 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
285 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
286 .. function:: atanh(x) |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
287 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
288 Return the inverse hyperbolic tangent of *x*. |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
289 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
290 .. versionadded:: 2.6 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
291 |
|
35bf8012a376
Move asinh documentation to the proper place.
Mark Dickinson <dickinsm@gmail.com>
parents:
46495
diff
changeset
|
292 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
293 .. function:: cosh(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
294 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
295 Return the hyperbolic cosine of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
296 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
297 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
298 .. function:: sinh(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
299 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
300 Return the hyperbolic sine of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
301 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
302 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
303 .. function:: tanh(x) |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
304 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
305 Return the hyperbolic tangent of *x*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
306 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
307 |
| 50235 | 308 Constants |
| 309 --------- | |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
310 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
311 .. data:: pi |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
312 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
313 The mathematical constant *pi*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
314 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
315 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
316 .. data:: e |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
317 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
318 The mathematical constant *e*. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
319 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
320 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
321 .. note:: |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
322 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
323 The :mod:`math` module consists mostly of thin wrappers around the platform C |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
324 math library functions. Behavior in exceptional cases is loosely specified |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
325 by the C standards, and Python inherits much of its math-function |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
326 error-reporting behavior from the platform C implementation. As a result, |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
327 the specific exceptions raised in error cases (and even whether some |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
328 arguments are considered to be exceptional at all) are not defined in any |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
329 useful cross-platform or cross-release way. For example, whether |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
330 ``math.log(0)`` returns ``-Inf`` or raises :exc:`ValueError` or |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
331 :exc:`OverflowError` isn't defined, and in cases where ``math.log(0)`` raises |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
332 :exc:`OverflowError`, ``math.log(0L)`` may raise :exc:`ValueError` instead. |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
333 |
|
46495
f641e505fff4
Correct documentation for math.pow;
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
334 All functions return a quiet *NaN* if at least one of the args is *NaN*. |
| 48904 | 335 Signaling *NaN*\s raise an exception. The exception type still depends on the |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
336 platform and libm implementation. It's usually :exc:`ValueError` for *EDOM* |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
337 and :exc:`OverflowError` for errno *ERANGE*. |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
338 |
| 46958 | 339 .. versionchanged:: 2.6 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
340 In earlier versions of Python the outcome of an operation with NaN as |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
341 input depended on platform and libm implementation. |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
342 |
|
42604
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
343 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
344 .. seealso:: |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
345 |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
346 Module :mod:`cmath` |
|
9e1529bf0442
Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
347 Complex number versions of many of these functions. |
