Mercurial > cpython-lru_cache-weakref
annotate Modules/cmathmodule.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 64bcef1702ad |
| children | 2f48ae5c8a94 |
| 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 */ | |
|
13685
129c9775cc19
Fix typo in previous patch.
Thomas Wouters <thomas@python.org>
parents:
13684
diff
changeset
|
20 staticforward Py_complex c_log(Py_complex); |
|
129c9775cc19
Fix typo in previous patch.
Thomas Wouters <thomas@python.org>
parents:
13684
diff
changeset
|
21 staticforward Py_complex c_prodi(Py_complex); |
|
129c9775cc19
Fix typo in previous patch.
Thomas Wouters <thomas@python.org>
parents:
13684
diff
changeset
|
22 staticforward Py_complex c_sqrt(Py_complex); |
| 3334 | 23 |
| 24 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
25 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
26 c_acos(Py_complex x) |
| 3334 | 27 { |
| 28 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
|
29 c_sqrt(c_diff(c_one,c_prod(x,x)))))))); |
| 3334 | 30 } |
| 31 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
32 static char c_acos_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
33 "acos(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
34 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
35 "Return the arc cosine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
36 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
37 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
38 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
39 c_acosh(Py_complex x) |
| 3334 | 40 { |
|
13169
b78b996e8ebc
Patch by Nadav Horesh to make acosh and asinh better.
Guido van Rossum <guido@python.org>
parents:
10403
diff
changeset
|
41 Py_complex z; |
|
b78b996e8ebc
Patch by Nadav Horesh to make acosh and asinh better.
Guido van Rossum <guido@python.org>
parents:
10403
diff
changeset
|
42 z = c_sqrt(c_half); |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
43 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
|
44 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
|
45 return c_sum(z, z); |
| 3334 | 46 } |
| 47 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
48 static char c_acosh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
49 "acosh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
50 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
51 "Return the hyperbolic arccosine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
52 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
53 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
54 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
55 c_asin(Py_complex x) |
| 3334 | 56 { |
|
16722
cc338a5c16e5
Bug #133297: cmath.asin is the same as cmath.asinh.
Tim Peters <tim.peters@gmail.com>
parents:
16708
diff
changeset
|
57 /* -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
|
58 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
|
59 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
|
60 return c_neg(c_prodi(c_log( |
|
844fde600a61
asin micro-optimization suggested in email.
Tim Peters <tim.peters@gmail.com>
parents:
16722
diff
changeset
|
61 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
|
62 ) ) ); |
| 3334 | 63 } |
| 64 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
65 static char c_asin_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
66 "asin(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
67 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
68 "Return the arc sine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
69 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
70 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
71 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
72 c_asinh(Py_complex x) |
| 3334 | 73 { |
|
9886
fae6d24b897b
Jim Ahlstrom patch: Watcom chokes on a long expression in c_asinh().
Guido van Rossum <guido@python.org>
parents:
9593
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 return c_sum(z, z); |
| 3334 | 79 } |
| 80 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
81 static char c_asinh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
82 "asinh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
83 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
84 "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
|
85 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
86 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
87 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
88 c_atan(Py_complex x) |
| 3334 | 89 { |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
90 return c_prod(c_halfi,c_log(c_quot(c_sum(c_i,x),c_diff(c_i,x)))); |
| 3334 | 91 } |
| 92 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
93 static char c_atan_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
94 "atan(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
95 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
96 "Return the arc tangent of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
97 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
98 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
99 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
100 c_atanh(Py_complex x) |
| 3334 | 101 { |
|
16708
57799f013aad
Rename some constants for easier readability.
Tim Peters <tim.peters@gmail.com>
parents:
16707
diff
changeset
|
102 return c_prod(c_half,c_log(c_quot(c_sum(c_one,x),c_diff(c_one,x)))); |
| 3334 | 103 } |
| 104 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
105 static char c_atanh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
106 "atanh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
107 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
108 "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
|
109 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
110 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
111 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
112 c_cos(Py_complex x) |
| 3334 | 113 { |
| 3771 | 114 Py_complex r; |
| 3334 | 115 r.real = cos(x.real)*cosh(x.imag); |
| 116 r.imag = -sin(x.real)*sinh(x.imag); | |
| 117 return r; | |
| 118 } | |
| 119 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
120 static char c_cos_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
121 "cos(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
122 "n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
123 "Return the cosine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
124 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
125 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
126 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
127 c_cosh(Py_complex x) |
| 3334 | 128 { |
| 3771 | 129 Py_complex r; |
| 3334 | 130 r.real = cos(x.imag)*cosh(x.real); |
| 131 r.imag = sin(x.imag)*sinh(x.real); | |
| 132 return r; | |
| 133 } | |
| 134 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
135 static char c_cosh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
136 "cosh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
137 "n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
138 "Return the hyperbolic cosine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
139 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
140 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
141 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
142 c_exp(Py_complex x) |
| 3334 | 143 { |
| 3771 | 144 Py_complex r; |
| 3334 | 145 double l = exp(x.real); |
| 146 r.real = l*cos(x.imag); | |
| 147 r.imag = l*sin(x.imag); | |
| 148 return r; | |
| 149 } | |
| 150 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
151 static char c_exp_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
152 "exp(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
153 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
154 "Return the exponential value e**x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
155 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
156 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
157 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
158 c_log(Py_complex x) |
| 3334 | 159 { |
| 3771 | 160 Py_complex r; |
| 3334 | 161 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
|
162 r.imag = atan2(x.imag, x.real); |
| 3334 | 163 r.real = log(l); |
| 164 return r; | |
| 165 } | |
| 166 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
167 static char c_log_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
168 "log(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
169 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
170 "Return the natural logarithm of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
171 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
172 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
173 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
174 c_log10(Py_complex x) |
| 3334 | 175 { |
| 3771 | 176 Py_complex r; |
| 3334 | 177 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
|
178 r.imag = atan2(x.imag, x.real)/log(10.); |
| 3334 | 179 r.real = log10(l); |
| 180 return r; | |
| 181 } | |
| 182 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
183 static char c_log10_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
184 "log10(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
185 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
186 "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
|
187 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
188 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
189 /* 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
|
190 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
191 c_prodi(Py_complex x) |
| 3334 | 192 { |
| 3771 | 193 Py_complex r; |
| 3334 | 194 r.real = -x.imag; |
| 195 r.imag = x.real; | |
| 196 return r; | |
| 197 } | |
| 198 | |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
199 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
200 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
201 c_sin(Py_complex x) |
| 3334 | 202 { |
| 3771 | 203 Py_complex r; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
204 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
|
205 r.imag = cos(x.real) * sinh(x.imag); |
| 3334 | 206 return r; |
| 207 } | |
| 208 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
209 static char c_sin_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
210 "sin(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
211 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
212 "Return the sine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
213 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
214 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
215 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
216 c_sinh(Py_complex x) |
| 3334 | 217 { |
| 3771 | 218 Py_complex r; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
219 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
|
220 r.imag = sin(x.imag) * cosh(x.real); |
| 3334 | 221 return r; |
| 222 } | |
| 223 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
224 static char c_sinh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
225 "sinh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
226 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
227 "Return the hyperbolic sine of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
228 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
229 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
230 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
231 c_sqrt(Py_complex x) |
| 3334 | 232 { |
| 3771 | 233 Py_complex r; |
| 3334 | 234 double s,d; |
| 235 if (x.real == 0. && x.imag == 0.) | |
| 236 r = x; | |
| 237 else { | |
| 238 s = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag))); | |
| 239 d = 0.5*x.imag/s; | |
| 240 if (x.real > 0.) { | |
| 241 r.real = s; | |
| 242 r.imag = d; | |
| 243 } | |
| 244 else if (x.imag >= 0.) { | |
| 245 r.real = d; | |
| 246 r.imag = s; | |
| 247 } | |
| 248 else { | |
| 249 r.real = -d; | |
| 250 r.imag = -s; | |
| 251 } | |
| 252 } | |
| 253 return r; | |
| 254 } | |
| 255 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
256 static char c_sqrt_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
257 "sqrt(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
258 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
259 "Return the square root of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
260 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
261 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
262 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
263 c_tan(Py_complex x) |
| 3334 | 264 { |
| 3771 | 265 Py_complex r; |
| 3334 | 266 double sr,cr,shi,chi; |
| 267 double rs,is,rc,ic; | |
| 268 double d; | |
| 269 sr = sin(x.real); | |
| 270 cr = cos(x.real); | |
| 271 shi = sinh(x.imag); | |
| 272 chi = cosh(x.imag); | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
273 rs = sr * chi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
274 is = cr * shi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
275 rc = cr * chi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
276 ic = -sr * shi; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
277 d = rc*rc + ic * ic; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
278 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
|
279 r.imag = (is*rc - rs*ic) / d; |
| 3334 | 280 return r; |
| 281 } | |
| 282 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
283 static char c_tan_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
284 "tan(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
285 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
286 "Return the tangent of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
287 |
|
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
288 |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
289 static Py_complex |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
290 c_tanh(Py_complex x) |
| 3334 | 291 { |
| 3771 | 292 Py_complex r; |
| 3334 | 293 double si,ci,shr,chr; |
| 294 double rs,is,rc,ic; | |
| 295 double d; | |
| 296 si = sin(x.imag); | |
| 297 ci = cos(x.imag); | |
| 298 shr = sinh(x.real); | |
| 299 chr = cosh(x.real); | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
300 rs = ci * shr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
301 is = si * chr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
302 rc = ci * chr; |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
303 ic = si * shr; |
| 3334 | 304 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
|
305 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
|
306 r.imag = (is*rc - rs*ic) / d; |
| 3334 | 307 return r; |
| 308 } | |
| 309 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
310 static char c_tanh_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
311 "tanh(x)\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
312 "\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
313 "Return the hyperbolic tangent of x."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
314 |
| 3334 | 315 |
| 316 /* And now the glue to make them available from Python: */ | |
| 317 | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
318 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13493
diff
changeset
|
319 math_error(void) |
| 3334 | 320 { |
| 321 if (errno == EDOM) | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
322 PyErr_SetString(PyExc_ValueError, "math domain error"); |
| 3334 | 323 else if (errno == ERANGE) |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
324 PyErr_SetString(PyExc_OverflowError, "math range error"); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
325 else /* Unexpected math error */ |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
326 PyErr_SetFromErrno(PyExc_ValueError); |
| 3334 | 327 return NULL; |
| 328 } | |
| 329 | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
330 static PyObject * |
|
13493
8bacf8631a11
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
331 math_1(PyObject *args, Py_complex (*func)(Py_complex)) |
| 3334 | 332 { |
| 3771 | 333 Py_complex x; |
| 3334 | 334 if (!PyArg_ParseTuple(args, "D", &x)) |
| 335 return NULL; | |
| 336 errno = 0; | |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4649
diff
changeset
|
337 PyFPE_START_PROTECT("complex function", return 0) |
| 3334 | 338 x = (*func)(x); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
339 PyFPE_END_PROTECT(x) |
|
19750
35b6a1d0b1e0
Rework the way we try to check for libm overflow, given that C99 no longer
Tim Peters <tim.peters@gmail.com>
parents:
19730
diff
changeset
|
340 Py_SET_ERANGE_IF_OVERFLOW(x.real); |
|
35b6a1d0b1e0
Rework the way we try to check for libm overflow, given that C99 no longer
Tim Peters <tim.peters@gmail.com>
parents:
19730
diff
changeset
|
341 Py_SET_ERANGE_IF_OVERFLOW(x.imag); |
| 3334 | 342 if (errno != 0) |
| 343 return math_error(); | |
| 344 else | |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
345 return PyComplex_FromCComplex(x); |
| 3334 | 346 } |
| 347 | |
| 348 #define FUNC1(stubname, func) \ | |
|
13493
8bacf8631a11
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
349 static PyObject * stubname(PyObject *self, PyObject *args) { \ |
| 3334 | 350 return math_1(args, func); \ |
| 351 } | |
| 352 | |
| 353 FUNC1(cmath_acos, c_acos) | |
| 354 FUNC1(cmath_acosh, c_acosh) | |
| 355 FUNC1(cmath_asin, c_asin) | |
| 356 FUNC1(cmath_asinh, c_asinh) | |
| 357 FUNC1(cmath_atan, c_atan) | |
| 358 FUNC1(cmath_atanh, c_atanh) | |
| 359 FUNC1(cmath_cos, c_cos) | |
| 360 FUNC1(cmath_cosh, c_cosh) | |
| 361 FUNC1(cmath_exp, c_exp) | |
| 362 FUNC1(cmath_log, c_log) | |
| 363 FUNC1(cmath_log10, c_log10) | |
| 364 FUNC1(cmath_sin, c_sin) | |
| 365 FUNC1(cmath_sinh, c_sinh) | |
| 366 FUNC1(cmath_sqrt, c_sqrt) | |
| 367 FUNC1(cmath_tan, c_tan) | |
| 368 FUNC1(cmath_tanh, c_tanh) | |
| 369 | |
| 370 | |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
371 static char module_doc[] = |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
372 "This module is always available. It provides access to mathematical\n" |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
373 "functions for complex numbers."; |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
374 |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
375 static PyMethodDef cmath_methods[] = { |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
376 {"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
|
377 {"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
|
378 {"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
|
379 {"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
|
380 {"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
|
381 {"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
|
382 {"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
|
383 {"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
|
384 {"exp", cmath_exp, METH_VARARGS, c_exp_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
385 {"log", cmath_log, METH_VARARGS, c_log_doc}, |
|
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
386 {"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
|
387 {"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
|
388 {"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
|
389 {"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
|
390 {"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
|
391 {"tanh", cmath_tanh, METH_VARARGS, c_tanh_doc}, |
| 3334 | 392 {NULL, NULL} /* sentinel */ |
| 393 }; | |
| 394 | |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
395 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13493
diff
changeset
|
396 initcmath(void) |
| 3334 | 397 { |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
398 PyObject *m, *d, *v; |
|
16707
9696c95d09b7
Mechanical edits just so I can read it.
Tim Peters <tim.peters@gmail.com>
parents:
13817
diff
changeset
|
399 |
|
9593
f22f769bf3d9
Added Doc strings -- by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
400 m = Py_InitModule3("cmath", cmath_methods, module_doc); |
|
4639
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
401 d = PyModule_GetDict(m); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
402 PyDict_SetItemString(d, "pi", |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
403 v = PyFloat_FromDouble(atan(1.0) * 4.0)); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
404 Py_DECREF(v); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
405 PyDict_SetItemString(d, "e", v = PyFloat_FromDouble(exp(1.0))); |
|
97ec9dfbb2b6
Renamed Grandly
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
406 Py_DECREF(v); |
| 3334 | 407 } |
