[Jython-checkins] jython: Trivial formatting in math.java and cmath.java.
jeff.allen
jython-checkins at python.org
Wed Dec 31 02:41:09 CET 2014
https://hg.python.org/jython/rev/f97b61bd9d8b
changeset: 7486:f97b61bd9d8b
user: Jeff Allen <ja.py at farowl.co.uk>
date: Mon Dec 29 23:29:45 2014 +0000
summary:
Trivial formatting in math.java and cmath.java.
White space, line wraps, braces ... , ahead of substantive changes.
files:
src/org/python/modules/cmath.java | 101 ++++++-----------
src/org/python/modules/math.java | 65 +++++-----
2 files changed, 69 insertions(+), 97 deletions(-)
diff --git a/src/org/python/modules/cmath.java b/src/org/python/modules/cmath.java
--- a/src/org/python/modules/cmath.java
+++ b/src/org/python/modules/cmath.java
@@ -8,6 +8,7 @@
import org.python.core.PyTuple;
public class cmath {
+
public static final PyFloat pi = new PyFloat(Math.PI);
public static final PyFloat e = new PyFloat(Math.E);
@@ -16,23 +17,17 @@
private static final PyComplex i = new PyComplex(0.0, 1.0);
private static final PyComplex half_i = new PyComplex(0.0, 0.5);
-// private static PyComplex c_prodi(PyComplex x) {
-// return (new PyComplex(-x.imag, x.real));
-// }
-
private static PyComplex c_prodi(PyComplex x) {
- return (PyComplex) x.__mul__(i);
+ return (PyComplex)x.__mul__(i);
}
-
private static boolean isNaN(PyComplex x) {
return Double.isNaN(x.real) || Double.isNaN(x.imag);
}
private static double abs(PyComplex x) {
boolean isNaN = isNaN(x);
- boolean isInfinite = !isNaN &&
- (Double.isInfinite(x.real) || Double.isInfinite(x.imag));
+ boolean isInfinite = !isNaN && (Double.isInfinite(x.real) || Double.isInfinite(x.imag));
if (isNaN) {
return Double.NaN;
}
@@ -89,7 +84,7 @@
// the result, and fill in the imaginary part as 0
return new PyComplex(obj.asDouble(), 0);
}
-
+
public static PyObject acos(PyObject in) {
PyComplex x = complexFromPyObject(in);
return c_prodi(log(x.__add__(i.__mul__(sqrt(one.__sub__(x.__mul__(x))))))).__neg__();
@@ -101,14 +96,14 @@
PyComplex b = sqrt(x.__add__(one));
PyComplex c = sqrt(half);
PyComplex r = log(c.__mul__(b.__add__(a)));
- return ((PyComplex) r.__add__(r));
+ return ((PyComplex)r.__add__(r));
}
public static PyComplex asin(PyObject in) {
PyComplex x = complexFromPyObject(in);
- PyComplex squared = (PyComplex) x.__mul__(x);
+ PyComplex squared = (PyComplex)x.__mul__(x);
PyComplex sq1_minus_xsq = sqrt(one.__sub__(squared));
- return (PyComplex) c_prodi(log(sq1_minus_xsq.__add__(c_prodi(x)))).__neg__();
+ return (PyComplex)c_prodi(log(sq1_minus_xsq.__add__(c_prodi(x)))).__neg__();
}
public static PyComplex asinh(PyObject in) {
@@ -117,41 +112,35 @@
PyComplex b = sqrt(x.__sub__(i));
PyComplex z = sqrt(half);
PyComplex r = log(z.__mul__(a.__add__(b)));
- return ((PyComplex) r.__add__(r));
+ return ((PyComplex)r.__add__(r));
}
public static PyComplex atan(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return (PyComplex) half_i.__mul__(log(i.__add__(x).__div__(
- i.__sub__(x))));
+ return (PyComplex)half_i.__mul__(log(i.__add__(x).__div__(i.__sub__(x))));
}
public static PyComplex atanh(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return (PyComplex) half.__mul__(log(one.__add__(x).__div__(
- one.__sub__(x))));
+ return (PyComplex)half.__mul__(log(one.__add__(x).__div__(one.__sub__(x))));
}
public static PyComplex cos(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return new PyComplex(
- Math.cos(x.real) * math.cosh(x.imag),
- -Math.sin(x.real) * math.sinh(x.imag));
+ return new PyComplex(Math.cos(x.real) * math.cosh(x.imag), -Math.sin(x.real)
+ * math.sinh(x.imag));
}
public static PyComplex cosh(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return new PyComplex(
- Math.cos(x.imag) * math.cosh(x.real),
- Math.sin(x.imag) * math.sinh(x.real));
+ return new PyComplex(Math.cos(x.imag) * math.cosh(x.real), Math.sin(x.imag)
+ * math.sinh(x.real));
}
public static PyComplex exp(PyObject in) {
PyComplex x = complexFromPyObject(in);
double l = Math.exp(x.real);
- return new PyComplex(
- l * Math.cos(x.imag),
- l * Math.sin(x.imag));
+ return new PyComplex(l * Math.cos(x.imag), l * Math.sin(x.imag));
}
public static PyComplex log(PyObject in) {
@@ -163,9 +152,7 @@
return PyComplex.NaN;
}
}
- return new PyComplex(
- Math.log(abs(x)),
- Math.atan2(x.imag, x.real));
+ return new PyComplex(Math.log(abs(x)), Math.atan2(x.imag, x.real));
}
public static double phase(PyObject in) {
@@ -175,12 +162,12 @@
public static PyTuple polar(PyObject in) {
PyComplex z = complexFromPyObject(in);
- if ((Double.isInfinite(z.real) && Double.isNaN(z.imag)) ||
- (Double.isInfinite(z.imag) && Double.isNaN(z.real))) {
+ if ((Double.isInfinite(z.real) && Double.isNaN(z.imag))
+ || (Double.isInfinite(z.imag) && Double.isNaN(z.real))) {
return new PyTuple(Py.newFloat(Double.POSITIVE_INFINITY), Py.newFloat(Double.NaN));
}
double phi = Math.atan2(z.imag, z.real);
- double r = Math.sqrt(z.real*z.real + z.imag*z.imag);
+ double r = Math.sqrt(z.real * z.real + z.imag * z.imag);
return new PyTuple(new PyFloat(r), new PyFloat(phi));
}
@@ -202,16 +189,13 @@
return new PyComplex(0.0, 0.0);
}
- return new PyComplex(
- r * Math.cos(phi),
- r * Math.sin(phi));
+ return new PyComplex(r * Math.cos(phi), r * Math.sin(phi));
}
/**
- * @param in
- *
- * @return <code>true</code> if in.real or in.imag is positive or negative
- * infinity
+ * @param in
+ *
+ * @return <code>true</code> if in.real or in.imag is positive or negative infinity
*/
public static boolean isinf(PyObject in) {
PyComplex x = complexFromPyObject(in);
@@ -219,8 +203,8 @@
}
/**
- * @param in
- *
+ * @param in
+ *
* @return <code>true</code> if in.real or in.imag is nan.
*/
public static boolean isnan(PyObject in) {
@@ -238,11 +222,10 @@
}
}
double l = abs(x);
- return new PyComplex(
- math.log10(new PyFloat(l)),
- Math.atan2(x.imag, x.real) / Math.log(10.0));
+ return new PyComplex(math.log10(new PyFloat(l)), Math.atan2(x.imag, x.real)
+ / Math.log(10.0));
}
-
+
public static PyComplex log(PyObject in, PyObject base) {
return log(complexFromPyObject(in), complexFromPyObject(base));
}
@@ -257,24 +240,20 @@
}
double l = abs(x);
PyComplex log_base = log(base);
- return (PyComplex) new PyComplex(
- math.log(new PyFloat(l)),
- Math.atan2(x.imag, x.real)).
- __div__(log_base);
+ return (PyComplex)new PyComplex(math.log(new PyFloat(l)), Math.atan2(x.imag, x.real))
+ .__div__(log_base);
}
public static PyComplex sin(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return new PyComplex(
- Math.sin(x.real) * math.cosh(x.imag),
- Math.cos(x.real) * math.sinh(x.imag));
+ return new PyComplex(Math.sin(x.real) * math.cosh(x.imag), Math.cos(x.real)
+ * math.sinh(x.imag));
}
public static PyComplex sinh(PyObject in) {
PyComplex x = complexFromPyObject(in);
- return new PyComplex(
- Math.cos(x.imag) * math.sinh(x.real),
- Math.sin(x.imag) * math.cosh(x.real));
+ return new PyComplex(Math.cos(x.imag) * math.sinh(x.real), Math.sin(x.imag)
+ * math.cosh(x.real));
}
public static PyComplex sqrt(PyObject in) {
@@ -302,9 +281,7 @@
if (x.real >= 0.0) {
return new PyComplex(t, x.imag / (2.0 * t));
} else {
- return new PyComplex(
- Math.abs(x.imag) / (2.0 * t),
- Math.copySign(1d, x.imag) * t);
+ return new PyComplex(Math.abs(x.imag) / (2.0 * t), Math.copySign(1d, x.imag) * t);
}
}
@@ -321,9 +298,7 @@
double ic = -sr * shi;
double d = rc * rc + ic * ic;
- return new PyComplex(
- ((rs * rc) + (is * ic)) / d,
- ((is * rc) - (rs * ic)) / d);
+ return new PyComplex(((rs * rc) + (is * ic)) / d, ((is * rc) - (rs * ic)) / d);
}
public static PyComplex tanh(PyObject in) {
@@ -339,8 +314,6 @@
double ic = si * shr;
double d = rc * rc + ic * ic;
- return new PyComplex(
- ((rs * rc) + (is * ic)) / d,
- ((is * rc) - (rs * ic)) / d);
+ return new PyComplex(((rs * rc) + (is * ic)) / d, ((is * rc) - (rs * ic)) / d);
}
}
diff --git a/src/org/python/modules/math.java b/src/org/python/modules/math.java
--- a/src/org/python/modules/math.java
+++ b/src/org/python/modules/math.java
@@ -9,16 +9,14 @@
import org.python.core.PyInteger;
import org.python.core.PyLong;
import org.python.core.PyObject;
-import org.python.core.PySystemState;
import org.python.core.PyTuple;
import org.python.core.__builtin__;
-import org.python.modules.math_erf;
-import org.python.modules.math_gamma;
public class math implements ClassDictInit {
+
public static PyFloat pi = new PyFloat(Math.PI);
public static PyFloat e = new PyFloat(Math.E);
-
+
private static final double ZERO = 0.0;
private static final double MINUS_ZERO = -0.0;
private static final double HALF = 0.5;
@@ -29,11 +27,12 @@
private static final double INF = Double.POSITIVE_INFINITY;
private static final double NINF = Double.NEGATIVE_INFINITY;
private static final double NAN = Double.NaN;
- private static final BigInteger MAX_LONG_BIGINTEGER = new BigInteger(String.valueOf(Long.MAX_VALUE));
- private static final BigInteger MIN_LONG_BIGINTEGER = new BigInteger(String.valueOf(Long.MIN_VALUE));
+ private static final BigInteger MAX_LONG_BIGINTEGER = new BigInteger(
+ String.valueOf(Long.MAX_VALUE));
+ private static final BigInteger MIN_LONG_BIGINTEGER = new BigInteger(
+ String.valueOf(Long.MIN_VALUE));
- public static void classDictInit(@SuppressWarnings("unused") PyObject dict) {
- }
+ public static void classDictInit(@SuppressWarnings("unused") PyObject dict) {}
public static double gamma(double v) {
return math_gamma.gamma(v);
@@ -73,7 +72,7 @@
}
return Math.acos(v);
}
-
+
public static double acosh(double v) {
final double ln2 = 6.93147180559945286227e-01;
final double large = 1 << 28;
@@ -105,7 +104,7 @@
}
return Math.asin(v);
}
-
+
public static double asinh(double v) {
if (isnan(v) || isinf(v)) {
return v;
@@ -125,11 +124,11 @@
if (v > large) {
temp = log(v) + ln2;
} else if (v > 2) {
- temp = log(2*v + 1/(sqrt(v*v+1)+v));
+ temp = log(2 * v + 1 / (sqrt(v * v + 1) + v));
} else if (v < small) {
- temp = v;
+ temp = v;
} else {
- temp = log1p(v + v*v/(1+sqrt(1+v*v)));
+ temp = log1p(v + v * v / (1 + sqrt(1 + v * v)));
}
return sign ? -temp : temp;
@@ -141,7 +140,7 @@
}
return Math.atan(v);
}
-
+
public static double atanh(double v) {
if (isnan(v)) {
return v;
@@ -420,10 +419,10 @@
x = -x;
sign = -1;
}
-
- for (; x < HALF; x *= TWO, exponent--); // needs an empty statement
- for (; x >= ONE; x *= HALF, exponent++); // needs an empty statement
+ for (; x < HALF; x *= TWO, exponent--) {}
+
+ for (; x >= ONE; x *= HALF, exponent++) {}
x *= sign;
}
@@ -471,20 +470,20 @@
public static double degrees(double v) {
return check(Math.toDegrees(v));
}
-
+
public static boolean isnan(double v) {
return Double.isNaN(v);
}
-
+
/**
* @param v
- *
+ *
* @return <code>true</code> if v is positive or negative infinity
*/
public static boolean isinf(double v) {
return Double.isInfinite(v);
}
-
+
public static double copysign(double v, double w) {
if (isnan(v)) {
return NAN;
@@ -494,7 +493,7 @@
}
return v *= MINUS_ONE;
}
-
+
public static PyLong factorial(double v) {
if (v == ZERO || v == ONE) {
return new PyLong(1);
@@ -517,14 +516,12 @@
public static double log1p(double v) {
return log(ONE + v);
}
-
+
public static double fsum(final PyObject iterable) {
- PyFloat result = (PyFloat)__builtin__.__import__("_fsum")
- .invoke("fsum", iterable);
+ PyFloat result = (PyFloat)__builtin__.__import__("_fsum").invoke("fsum", iterable);
return result.asDouble();
}
-
private static double calculateLongLog(PyLong v) {
int exp[] = new int[1];
double x = v.scaledDoubleValue(exp);
@@ -563,7 +560,7 @@
}
return Math.log10(v);
}
-
+
private static boolean isninf(double v) {
return v == NINF;
}
@@ -571,7 +568,7 @@
private static boolean ispinf(double v) {
return v == INF;
}
-
+
/**
* work around special Math.signum() behaviour for positive and negative zero
*/
@@ -592,20 +589,22 @@
}
private static double check(double v) {
- if (isnan(v))
+ if (isnan(v)) {
throwMathDomainValueError();
- if (isinf(v))
+ }
+ if (isinf(v)) {
throw Py.OverflowError("math range error");
+ }
return v;
}
-
+
private static double checkOverflow(double v) {
if (isinf(v)) {
throw Py.OverflowError("math range error");
}
return v;
}
-
+
/**
* convert a PyObject into a long between Long.MIN_VALUE and Long.MAX_VALUE
*/
@@ -615,7 +614,7 @@
}
return pyo.asLong();
}
-
+
/**
* convert a PyLong into a long between Long.MIN_VALUE and Long.MAX_VALUE
*/
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list