88import org .python .core .PyTuple ;
99
1010public class cmath {
11+
1112 public static final PyFloat pi = new PyFloat (Math .PI );
1213 public static final PyFloat e = new PyFloat (Math .E );
1314
@@ -16,23 +17,17 @@ public class cmath {
1617 private static final PyComplex i = new PyComplex (0.0 , 1.0 );
1718 private static final PyComplex half_i = new PyComplex (0.0 , 0.5 );
1819
19- // private static PyComplex c_prodi(PyComplex x) {
20- // return (new PyComplex(-x.imag, x.real));
21- // }
22-
2320 private static PyComplex c_prodi (PyComplex x ) {
24- return (PyComplex ) x .__mul__ (i );
21+ return (PyComplex )x .__mul__ (i );
2522 }
2623
27-
2824 private static boolean isNaN (PyComplex x ) {
2925 return Double .isNaN (x .real ) || Double .isNaN (x .imag );
3026 }
3127
3228 private static double abs (PyComplex x ) {
3329 boolean isNaN = isNaN (x );
34- boolean isInfinite = !isNaN &&
35- (Double .isInfinite (x .real ) || Double .isInfinite (x .imag ));
30+ boolean isInfinite = !isNaN && (Double .isInfinite (x .real ) || Double .isInfinite (x .imag ));
3631 if (isNaN ) {
3732 return Double .NaN ;
3833 }
@@ -89,7 +84,7 @@ private static PyComplex complexFromPyObject(PyObject obj) {
8984 // the result, and fill in the imaginary part as 0
9085 return new PyComplex (obj .asDouble (), 0 );
9186 }
92-
87+
9388 public static PyObject acos (PyObject in ) {
9489 PyComplex x = complexFromPyObject (in );
9590 return c_prodi (log (x .__add__ (i .__mul__ (sqrt (one .__sub__ (x .__mul__ (x ))))))).__neg__ ();
@@ -101,14 +96,14 @@ public static PyComplex acosh(PyObject in) {
10196 PyComplex b = sqrt (x .__add__ (one ));
10297 PyComplex c = sqrt (half );
10398 PyComplex r = log (c .__mul__ (b .__add__ (a )));
104- return ((PyComplex ) r .__add__ (r ));
99+ return ((PyComplex )r .__add__ (r ));
105100 }
106101
107102 public static PyComplex asin (PyObject in ) {
108103 PyComplex x = complexFromPyObject (in );
109- PyComplex squared = (PyComplex ) x .__mul__ (x );
104+ PyComplex squared = (PyComplex )x .__mul__ (x );
110105 PyComplex sq1_minus_xsq = sqrt (one .__sub__ (squared ));
111- return (PyComplex ) c_prodi (log (sq1_minus_xsq .__add__ (c_prodi (x )))).__neg__ ();
106+ return (PyComplex )c_prodi (log (sq1_minus_xsq .__add__ (c_prodi (x )))).__neg__ ();
112107 }
113108
114109 public static PyComplex asinh (PyObject in ) {
@@ -117,41 +112,35 @@ public static PyComplex asinh(PyObject in) {
117112 PyComplex b = sqrt (x .__sub__ (i ));
118113 PyComplex z = sqrt (half );
119114 PyComplex r = log (z .__mul__ (a .__add__ (b )));
120- return ((PyComplex ) r .__add__ (r ));
115+ return ((PyComplex )r .__add__ (r ));
121116 }
122117
123118 public static PyComplex atan (PyObject in ) {
124119 PyComplex x = complexFromPyObject (in );
125- return (PyComplex ) half_i .__mul__ (log (i .__add__ (x ).__div__ (
126- i .__sub__ (x ))));
120+ return (PyComplex )half_i .__mul__ (log (i .__add__ (x ).__div__ (i .__sub__ (x ))));
127121 }
128122
129123 public static PyComplex atanh (PyObject in ) {
130124 PyComplex x = complexFromPyObject (in );
131- return (PyComplex ) half .__mul__ (log (one .__add__ (x ).__div__ (
132- one .__sub__ (x ))));
125+ return (PyComplex )half .__mul__ (log (one .__add__ (x ).__div__ (one .__sub__ (x ))));
133126 }
134127
135128 public static PyComplex cos (PyObject in ) {
136129 PyComplex x = complexFromPyObject (in );
137- return new PyComplex (
138- Math .cos (x .real ) * math .cosh (x .imag ),
139- -Math .sin (x .real ) * math .sinh (x .imag ));
130+ return new PyComplex (Math .cos (x .real ) * math .cosh (x .imag ), -Math .sin (x .real )
131+ * math .sinh (x .imag ));
140132 }
141133
142134 public static PyComplex cosh (PyObject in ) {
143135 PyComplex x = complexFromPyObject (in );
144- return new PyComplex (
145- Math .cos (x .imag ) * math .cosh (x .real ),
146- Math .sin (x .imag ) * math .sinh (x .real ));
136+ return new PyComplex (Math .cos (x .imag ) * math .cosh (x .real ), Math .sin (x .imag )
137+ * math .sinh (x .real ));
147138 }
148139
149140 public static PyComplex exp (PyObject in ) {
150141 PyComplex x = complexFromPyObject (in );
151142 double l = Math .exp (x .real );
152- return new PyComplex (
153- l * Math .cos (x .imag ),
154- l * Math .sin (x .imag ));
143+ return new PyComplex (l * Math .cos (x .imag ), l * Math .sin (x .imag ));
155144 }
156145
157146 public static PyComplex log (PyObject in ) {
@@ -163,9 +152,7 @@ public static PyComplex log(PyObject in) {
163152 return PyComplex .NaN ;
164153 }
165154 }
166- return new PyComplex (
167- Math .log (abs (x )),
168- Math .atan2 (x .imag , x .real ));
155+ return new PyComplex (Math .log (abs (x )), Math .atan2 (x .imag , x .real ));
169156 }
170157
171158 public static double phase (PyObject in ) {
@@ -175,12 +162,12 @@ public static double phase(PyObject in) {
175162
176163 public static PyTuple polar (PyObject in ) {
177164 PyComplex z = complexFromPyObject (in );
178- if ((Double .isInfinite (z .real ) && Double .isNaN (z .imag )) ||
179- (Double .isInfinite (z .imag ) && Double .isNaN (z .real ))) {
165+ if ((Double .isInfinite (z .real ) && Double .isNaN (z .imag ))
166+ || (Double .isInfinite (z .imag ) && Double .isNaN (z .real ))) {
180167 return new PyTuple (Py .newFloat (Double .POSITIVE_INFINITY ), Py .newFloat (Double .NaN ));
181168 }
182169 double phi = Math .atan2 (z .imag , z .real );
183- double r = Math .sqrt (z .real * z .real + z .imag * z .imag );
170+ double r = Math .sqrt (z .real * z .real + z .imag * z .imag );
184171 return new PyTuple (new PyFloat (r ), new PyFloat (phi ));
185172 }
186173
@@ -202,25 +189,22 @@ public static PyComplex rect(double r, double phi) {
202189 return new PyComplex (0.0 , 0.0 );
203190 }
204191
205- return new PyComplex (
206- r * Math .cos (phi ),
207- r * Math .sin (phi ));
192+ return new PyComplex (r * Math .cos (phi ), r * Math .sin (phi ));
208193 }
209194
210195 /**
211- * @param in
212- *
213- * @return <code>true</code> if in.real or in.imag is positive or negative
214- * infinity
196+ * @param in
197+ *
198+ * @return <code>true</code> if in.real or in.imag is positive or negative infinity
215199 */
216200 public static boolean isinf (PyObject in ) {
217201 PyComplex x = complexFromPyObject (in );
218202 return Double .isInfinite (x .real ) || Double .isInfinite (x .imag );
219203 }
220204
221205 /**
222- * @param in
223- *
206+ * @param in
207+ *
224208 * @return <code>true</code> if in.real or in.imag is nan.
225209 */
226210 public static boolean isnan (PyObject in ) {
@@ -238,11 +222,10 @@ public static PyComplex log10(PyObject in) {
238222 }
239223 }
240224 double l = abs (x );
241- return new PyComplex (
242- math .log10 (new PyFloat (l )),
243- Math .atan2 (x .imag , x .real ) / Math .log (10.0 ));
225+ return new PyComplex (math .log10 (new PyFloat (l )), Math .atan2 (x .imag , x .real )
226+ / Math .log (10.0 ));
244227 }
245-
228+
246229 public static PyComplex log (PyObject in , PyObject base ) {
247230 return log (complexFromPyObject (in ), complexFromPyObject (base ));
248231 }
@@ -257,24 +240,20 @@ public static PyComplex log(PyComplex x, PyComplex base) {
257240 }
258241 double l = abs (x );
259242 PyComplex log_base = log (base );
260- return (PyComplex ) new PyComplex (
261- math .log (new PyFloat (l )),
262- Math .atan2 (x .imag , x .real )).
263- __div__ (log_base );
243+ return (PyComplex )new PyComplex (math .log (new PyFloat (l )), Math .atan2 (x .imag , x .real ))
244+ .__div__ (log_base );
264245 }
265246
266247 public static PyComplex sin (PyObject in ) {
267248 PyComplex x = complexFromPyObject (in );
268- return new PyComplex (
269- Math .sin (x .real ) * math .cosh (x .imag ),
270- Math .cos (x .real ) * math .sinh (x .imag ));
249+ return new PyComplex (Math .sin (x .real ) * math .cosh (x .imag ), Math .cos (x .real )
250+ * math .sinh (x .imag ));
271251 }
272252
273253 public static PyComplex sinh (PyObject in ) {
274254 PyComplex x = complexFromPyObject (in );
275- return new PyComplex (
276- Math .cos (x .imag ) * math .sinh (x .real ),
277- Math .sin (x .imag ) * math .cosh (x .real ));
255+ return new PyComplex (Math .cos (x .imag ) * math .sinh (x .real ), Math .sin (x .imag )
256+ * math .cosh (x .real ));
278257 }
279258
280259 public static PyComplex sqrt (PyObject in ) {
@@ -302,9 +281,7 @@ public static PyComplex sqrt(PyObject in) {
302281 if (x .real >= 0.0 ) {
303282 return new PyComplex (t , x .imag / (2.0 * t ));
304283 } else {
305- return new PyComplex (
306- Math .abs (x .imag ) / (2.0 * t ),
307- Math .copySign (1d , x .imag ) * t );
284+ return new PyComplex (Math .abs (x .imag ) / (2.0 * t ), Math .copySign (1d , x .imag ) * t );
308285 }
309286 }
310287
@@ -321,9 +298,7 @@ public static PyComplex tan(PyObject in) {
321298 double ic = -sr * shi ;
322299 double d = rc * rc + ic * ic ;
323300
324- return new PyComplex (
325- ((rs * rc ) + (is * ic )) / d ,
326- ((is * rc ) - (rs * ic )) / d );
301+ return new PyComplex (((rs * rc ) + (is * ic )) / d , ((is * rc ) - (rs * ic )) / d );
327302 }
328303
329304 public static PyComplex tanh (PyObject in ) {
@@ -339,8 +314,6 @@ public static PyComplex tanh(PyObject in) {
339314 double ic = si * shr ;
340315 double d = rc * rc + ic * ic ;
341316
342- return new PyComplex (
343- ((rs * rc ) + (is * ic )) / d ,
344- ((is * rc ) - (rs * ic )) / d );
317+ return new PyComplex (((rs * rc ) + (is * ic )) / d , ((is * rc ) - (rs * ic )) / d );
345318 }
346319}
0 commit comments