Mercurial > cpython-lru_cache-weakref
annotate Modules/cmathmodule.c @ 39496:352ffe77b71d legacy-trunk
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 14 Aug 2006 21:42:55 +0000 |
| parents | 1af7f719ed28 |
| children | b69f443ef480 |
| rev | line source |
|---|---|
| 3334 | 1 /* Complex math module */ |
| 2 | |
| 3 /* much code borrowed from mathmodule.c */ | |
| 4 | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
5 #include "Python.h" |
| 3334 | 6 |
| 7 #ifndef M_PI | |
| 8 #define M_PI (3.141592653589793239) | |
| 9 #endif | |
| 10 | |
| 11 /* First, the C functions that do the real work */ | |
| 12 | |
| 13 /* constants */ | |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
14 static Py_complex c_one = {1., 0.}; |
| 3771 | 15 static Py_complex c_half = {0.5, 0.}; |
| 16 static Py_complex c_i = {0., 1.}; | |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
17 static Py_complex c_halfi = {0., 0.5}; |
| 3334 | 18 |
| 19 /* forward declarations */ | |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
20 static Py_complex c_log(Py_complex); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
21 static Py_complex c_prodi(Py_complex); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
22 static Py_complex c_sqrt(Py_complex); |
|
32350
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
23 static PyObject * math_error(void); |
| 3334 | 24 |
| 25 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
26 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
27 c_acos(Py_complex x) |
| 3334 | 28 { |
| 29 return c_neg(c_prodi(c_log(c_sum(x,c_prod(c_i, | |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
30 c_sqrt(c_diff(c_one,c_prod(x,x)))))))); |
| 3334 | 31 } |
| 32 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
33 PyDoc_STRVAR(c_acos_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
34 "acos(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
35 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
36 "Return the arc cosine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
37 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
38 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
39 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
40 c_acosh(Py_complex x) |
| 3334 | 41 { |
|
13169
b78b996e8ebc
Patch by Nadav Horesh to make acosh and asinh better.
Guido van Rossum <guido@python.org>
parents:
10403
diff
changeset
|
42 Py_complex z; |
|
b78b996e8ebc
Patch by Nadav Horesh to make acosh and asinh better.
Guido van Rossum <guido@python.org>
parents:
10403
diff
changeset
|
43 z = c_sqrt(c_half); |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
44 z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x,c_one)), |
|
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
45 c_sqrt(c_diff(x,c_one))))); |
|
13169
b78b996e8ebc
Patch by Nadav Horesh to make acosh and asinh better.
Guido van Rossum <guido@python.org>
parents:
10403
diff
changeset
|
46 return c_sum(z, z); |
| 3334 | 47 } |
| 48 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
49 PyDoc_STRVAR(c_acosh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
50 "acosh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
51 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
52 "Return the hyperbolic arccosine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
53 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
54 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
55 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
56 c_asin(Py_complex x) |
| 3334 | 57 { |
|
16722
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
58 /* -i * log[(sqrt(1-x**2) + i*x] */ |
|
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
59 const Py_complex squared = c_prod(x, x); |
|
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
60 const Py_complex sqrt_1_minus_x_sq = c_sqrt(c_diff(c_one, squared)); |
|
16738
844fde600a61
asin micro-optimization suggested in email.
Tim Peters <tim.peters@gmail.com>
parents:
16722
diff
changeset
|
61 return c_neg(c_prodi(c_log( |
|
844fde600a61
asin micro-optimization suggested in email.
Tim Peters <tim.peters@gmail.com>
parents:
16722
diff
changeset
|
62 c_sum(sqrt_1_minus_x_sq, c_prodi(x)) |
|
844fde600a61
asin micro-optimization suggested in email.
Tim Peters <tim.peters@gmail.com>
parents:
16722
diff
changeset
|
63 ) ) ); |
| 3334 | 64 } |
| 65 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
66 PyDoc_STRVAR(c_asin_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
67 "asin(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
68 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
69 "Return the arc sine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
70 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
71 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
72 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
73 c_asinh(Py_complex x) |
| 3334 | 74 { |
|
9886
fae6d24b897b
Jim Ahlstrom patch: Watcom chokes on a long expression in c_asinh().
Guido van Rossum <guido@python.org>
parents:
9593
diff
changeset
|
75 Py_complex z; |
|
16722
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
76 z = c_sqrt(c_half); |
|
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
77 z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)), |
|
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
78 c_sqrt(c_diff(x, c_i))))); |
|
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
79 return c_sum(z, z); |
| 3334 | 80 } |
| 81 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
82 PyDoc_STRVAR(c_asinh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
83 "asinh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
84 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
85 "Return the hyperbolic arc sine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
86 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
87 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
88 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
89 c_atan(Py_complex x) |
| 3334 | 90 { |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
91 return c_prod(c_halfi,c_log(c_quot(c_sum(c_i,x),c_diff(c_i,x)))); |
| 3334 | 92 } |
| 93 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
94 PyDoc_STRVAR(c_atan_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
95 "atan(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
96 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
97 "Return the arc tangent of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
98 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
99 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
100 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
101 c_atanh(Py_complex x) |
| 3334 | 102 { |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
103 return c_prod(c_half,c_log(c_quot(c_sum(c_one,x),c_diff(c_one,x)))); |
| 3334 | 104 } |
| 105 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
106 PyDoc_STRVAR(c_atanh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
107 "atanh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
108 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
109 "Return the hyperbolic arc tangent of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
110 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
111 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
112 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
113 c_cos(Py_complex x) |
| 3334 | 114 { |
| 3771 | 115 Py_complex r; |
| 3334 | 116 r.real = cos(x.real)*cosh(x.imag); |
| 117 r.imag = -sin(x.real)*sinh(x.imag); | |
| 118 return r; | |
| 119 } | |
| 120 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
121 PyDoc_STRVAR(c_cos_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
122 "cos(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
123 "n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
124 "Return the cosine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
125 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
126 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
127 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
128 c_cosh(Py_complex x) |
| 3334 | 129 { |
| 3771 | 130 Py_complex r; |
| 3334 | 131 r.real = cos(x.imag)*cosh(x.real); |
| 132 r.imag = sin(x.imag)*sinh(x.real); | |
| 133 return r; | |
| 134 } | |
| 135 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
136 PyDoc_STRVAR(c_cosh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
137 "cosh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
138 "n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
139 "Return the hyperbolic cosine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
140 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
141 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
142 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
143 c_exp(Py_complex x) |
| 3334 | 144 { |
| 3771 | 145 Py_complex r; |
| 3334 | 146 double l = exp(x.real); |
| 147 r.real = l*cos(x.imag); | |
| 148 r.imag = l*sin(x.imag); | |
| 149 return r; | |
| 150 } | |
| 151 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
152 PyDoc_STRVAR(c_exp_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
153 "exp(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
154 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
155 "Return the exponential value e**x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
156 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
157 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
158 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
159 c_log(Py_complex x) |
| 3334 | 160 { |
| 3771 | 161 Py_complex r; |
| 3334 | 162 double l = hypot(x.real,x.imag); |
|
19758
64bcef1702ad
Revert parts of patch #453627, documenting the resulting test failures
Martin v. Löwis <martin@v.loewis.de>
parents:
19750
diff
changeset
|
163 r.imag = atan2(x.imag, x.real); |
| 3334 | 164 r.real = log(l); |
| 165 return r; | |
| 166 } | |
| 167 | |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
168 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
169 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
170 c_log10(Py_complex x) |
| 3334 | 171 { |
| 3771 | 172 Py_complex r; |
| 3334 | 173 double l = hypot(x.real,x.imag); |
|
19758
64bcef1702ad
Revert parts of patch #453627, documenting the resulting test failures
Martin v. Löwis <martin@v.loewis.de>
parents:
19750
diff
changeset
|
174 r.imag = atan2(x.imag, x.real)/log(10.); |
| 3334 | 175 r.real = log10(l); |
| 176 return r; | |
| 177 } | |
| 178 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
179 PyDoc_STRVAR(c_log10_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
180 "log10(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
181 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
182 "Return the base-10 logarithm of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
183 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
184 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
185 /* internal function not available from Python */ |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
186 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
187 c_prodi(Py_complex x) |
| 3334 | 188 { |
| 3771 | 189 Py_complex r; |
| 3334 | 190 r.real = -x.imag; |
| 191 r.imag = x.real; | |
| 192 return r; | |
| 193 } | |
| 194 | |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
195 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
196 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
197 c_sin(Py_complex x) |
| 3334 | 198 { |
| 3771 | 199 Py_complex r; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
200 r.real = sin(x.real) * cosh(x.imag); |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
201 r.imag = cos(x.real) * sinh(x.imag); |
| 3334 | 202 return r; |
| 203 } | |
| 204 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
205 PyDoc_STRVAR(c_sin_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
206 "sin(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
207 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
208 "Return the sine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
209 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
210 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
211 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
212 c_sinh(Py_complex x) |
| 3334 | 213 { |
| 3771 | 214 Py_complex r; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
215 r.real = cos(x.imag) * sinh(x.real); |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
216 r.imag = sin(x.imag) * cosh(x.real); |
| 3334 | 217 return r; |
| 218 } | |
| 219 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
220 PyDoc_STRVAR(c_sinh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
221 "sinh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
222 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
223 "Return the hyperbolic sine of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
224 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
225 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
226 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
227 c_sqrt(Py_complex x) |
| 3334 | 228 { |
| 3771 | 229 Py_complex r; |
| 3334 | 230 double s,d; |
| 231 if (x.real == 0. && x.imag == 0.) | |
| 232 r = x; | |
| 233 else { | |
| 234 s = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag))); | |
| 235 d = 0.5*x.imag/s; | |
| 236 if (x.real > 0.) { | |
| 237 r.real = s; | |
| 238 r.imag = d; | |
| 239 } | |
| 240 else if (x.imag >= 0.) { | |
| 241 r.real = d; | |
| 242 r.imag = s; | |
| 243 } | |
| 244 else { | |
| 245 r.real = -d; | |
| 246 r.imag = -s; | |
| 247 } | |
| 248 } | |
| 249 return r; | |
| 250 } | |
| 251 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
252 PyDoc_STRVAR(c_sqrt_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
253 "sqrt(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
254 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
255 "Return the square root of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
256 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
257 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
258 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
259 c_tan(Py_complex x) |
| 3334 | 260 { |
| 3771 | 261 Py_complex r; |
| 3334 | 262 double sr,cr,shi,chi; |
| 263 double rs,is,rc,ic; | |
| 264 double d; | |
| 265 sr = sin(x.real); | |
| 266 cr = cos(x.real); | |
| 267 shi = sinh(x.imag); | |
| 268 chi = cosh(x.imag); | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
269 rs = sr * chi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
270 is = cr * shi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
271 rc = cr * chi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
272 ic = -sr * shi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
273 d = rc*rc + ic * ic; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
274 r.real = (rs*rc + is*ic) / d; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
275 r.imag = (is*rc - rs*ic) / d; |
| 3334 | 276 return r; |
| 277 } | |
| 278 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
279 PyDoc_STRVAR(c_tan_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
280 "tan(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
281 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
282 "Return the tangent of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
283 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
284 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
285 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
286 c_tanh(Py_complex x) |
| 3334 | 287 { |
| 3771 | 288 Py_complex r; |
| 3334 | 289 double si,ci,shr,chr; |
| 290 double rs,is,rc,ic; | |
| 291 double d; | |
| 292 si = sin(x.imag); | |
| 293 ci = cos(x.imag); | |
| 294 shr = sinh(x.real); | |
| 295 chr = cosh(x.real); | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
296 rs = ci * shr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
297 is = si * chr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
298 rc = ci * chr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
299 ic = si * shr; |
| 3334 | 300 d = rc*rc + ic*ic; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
301 r.real = (rs*rc + is*ic) / d; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
302 r.imag = (is*rc - rs*ic) / d; |
| 3334 | 303 return r; |
| 304 } | |
| 305 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
306 PyDoc_STRVAR(c_tanh_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
307 "tanh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
308 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
309 "Return the hyperbolic tangent of x."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
310 |
|
32350
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
311 static PyObject * |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
312 cmath_log(PyObject *self, PyObject *args) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
313 { |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
314 Py_complex x; |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
315 Py_complex y; |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
316 |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
317 if (!PyArg_ParseTuple(args, "D|D", &x, &y)) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
318 return NULL; |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
319 |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
320 errno = 0; |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
321 PyFPE_START_PROTECT("complex function", return 0) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
322 x = c_log(x); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
323 if (PyTuple_GET_SIZE(args) == 2) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
324 x = c_quot(x, c_log(y)); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
325 PyFPE_END_PROTECT(x) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
326 if (errno != 0) |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
327 return math_error(); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
328 Py_ADJUST_ERANGE2(x.real, x.imag); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
329 return PyComplex_FromCComplex(x); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
330 } |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
331 |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
332 PyDoc_STRVAR(cmath_log_doc, |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
333 "log(x[, base]) -> the logarithm of x to the given base.\n\ |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
334 If the base not specified, returns the natural logarithm (base e) of x."); |
|
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
335 |
| 3334 | 336 |
| 337 /* And now the glue to make them available from Python: */ | |
| 338 | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
339 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13493
diff
changeset
|
340 math_error(void) |
| 3334 | 341 { |
| 342 if (errno == EDOM) | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
343 PyErr_SetString(PyExc_ValueError, "math domain error"); |
| 3334 | 344 else if (errno == ERANGE) |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
345 PyErr_SetString(PyExc_OverflowError, "math range error"); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
346 else /* Unexpected math error */ |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
347 PyErr_SetFromErrno(PyExc_ValueError); |
| 3334 | 348 return NULL; |
| 349 } | |
| 350 | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
351 static PyObject * |
|
13493
8bacf8631a11
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
352 math_1(PyObject *args, Py_complex (*func)(Py_complex)) |
| 3334 | 353 { |
| 3771 | 354 Py_complex x; |
| 3334 | 355 if (!PyArg_ParseTuple(args, "D", &x)) |
| 356 return NULL; | |
| 357 errno = 0; | |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4649
diff
changeset
|
358 PyFPE_START_PROTECT("complex function", return 0) |
| 3334 | 359 x = (*func)(x); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
360 PyFPE_END_PROTECT(x) |
|
22227
2f48ae5c8a94
backport tim_one's checkin of
Michael W. Hudson <mwh@python.net>
parents:
19758
diff
changeset
|
361 Py_ADJUST_ERANGE2(x.real, x.imag); |
| 3334 | 362 if (errno != 0) |
| 363 return math_error(); | |
| 364 else | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
365 return PyComplex_FromCComplex(x); |
| 3334 | 366 } |
| 367 | |
| 368 #define FUNC1(stubname, func) \ | |
|
13493
8bacf8631a11
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
369 static PyObject * stubname(PyObject *self, PyObject *args) { \ |
| 3334 | 370 return math_1(args, func); \ |
| 371 } | |
| 372 | |
| 373 FUNC1(cmath_acos, c_acos) | |
| 374 FUNC1(cmath_acosh, c_acosh) | |
| 375 FUNC1(cmath_asin, c_asin) | |
| 376 FUNC1(cmath_asinh, c_asinh) | |
| 377 FUNC1(cmath_atan, c_atan) | |
| 378 FUNC1(cmath_atanh, c_atanh) | |
| 379 FUNC1(cmath_cos, c_cos) | |
| 380 FUNC1(cmath_cosh, c_cosh) | |
| 381 FUNC1(cmath_exp, c_exp) | |
| 382 FUNC1(cmath_log10, c_log10) | |
| 383 FUNC1(cmath_sin, c_sin) | |
| 384 FUNC1(cmath_sinh, c_sinh) | |
| 385 FUNC1(cmath_sqrt, c_sqrt) | |
| 386 FUNC1(cmath_tan, c_tan) | |
| 387 FUNC1(cmath_tanh, c_tanh) | |
| 388 | |
| 389 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
390 PyDoc_STRVAR(module_doc, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
391 "This module is always available. It provides access to mathematical\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22722
diff
changeset
|
392 "functions for complex numbers."); |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
393 |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
394 static PyMethodDef cmath_methods[] = { |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
395 {"acos", cmath_acos, METH_VARARGS, c_acos_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
396 {"acosh", cmath_acosh, METH_VARARGS, c_acosh_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
397 {"asin", cmath_asin, METH_VARARGS, c_asin_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
398 {"asinh", cmath_asinh, METH_VARARGS, c_asinh_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
399 {"atan", cmath_atan, METH_VARARGS, c_atan_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
400 {"atanh", cmath_atanh, METH_VARARGS, c_atanh_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
401 {"cos", cmath_cos, METH_VARARGS, c_cos_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
402 {"cosh", cmath_cosh, METH_VARARGS, c_cosh_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
403 {"exp", cmath_exp, METH_VARARGS, c_exp_doc}, |
|
32350
11c31a98dfd6
Patch #826074: cmath.log optional base argument, fixes #823209
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
404 {"log", cmath_log, METH_VARARGS, cmath_log_doc}, |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
405 {"log10", cmath_log10, METH_VARARGS, c_log10_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
406 {"sin", cmath_sin, METH_VARARGS, c_sin_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
407 {"sinh", cmath_sinh, METH_VARARGS, c_sinh_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
408 {"sqrt", cmath_sqrt, METH_VARARGS, c_sqrt_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
409 {"tan", cmath_tan, METH_VARARGS, c_tan_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
410 {"tanh", cmath_tanh, METH_VARARGS, c_tanh_doc}, |
| 3334 | 411 {NULL, NULL} /* sentinel */ |
| 412 }; | |
| 413 | |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
414 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13493
diff
changeset
|
415 initcmath(void) |
| 3334 | 416 { |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22227
diff
changeset
|
417 PyObject *m; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
418 |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
419 m = Py_InitModule3("cmath", cmath_methods, module_doc); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32350
diff
changeset
|
420 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32350
diff
changeset
|
421 return; |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22227
diff
changeset
|
422 |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22227
diff
changeset
|
423 PyModule_AddObject(m, "pi", |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22227
diff
changeset
|
424 PyFloat_FromDouble(atan(1.0) * 4.0)); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22227
diff
changeset
|
425 PyModule_AddObject(m, "e", PyFloat_FromDouble(exp(1.0))); |
| 3334 | 426 } |
