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