[Jython-checkins] jython: Formatting changes only.

jeff.allen jython-checkins at python.org
Thu Apr 24 00:04:06 CEST 2014


http://hg.python.org/jython/rev/56db40fe0a8b
changeset:   7214:56db40fe0a8b
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Thu Apr 17 13:35:02 2014 +0100
summary:
  Formatting changes only.
Reformatting, curly brackets, etc. in modules ahead of substantive change.

files:
  src/org/python/core/PyComplex.java |   99 +++-----
  src/org/python/core/PyFloat.java   |  190 ++++++++--------
  2 files changed, 133 insertions(+), 156 deletions(-)


diff --git a/src/org/python/core/PyComplex.java b/src/org/python/core/PyComplex.java
--- a/src/org/python/core/PyComplex.java
+++ b/src/org/python/core/PyComplex.java
@@ -1,13 +1,10 @@
-/*
- * Copyright (c) Corporation for National Research Initiatives
- * Copyright (c) Jython Developers
- */
+// Copyright (c) Corporation for National Research Initiatives
+// Copyright (c) Jython Developers
 package org.python.core;
 
 import org.python.core.stringlib.Formatter;
 import org.python.core.stringlib.InternalFormatSpec;
 import org.python.core.stringlib.InternalFormatSpecParser;
-
 import org.python.expose.ExposedGet;
 import org.python.expose.ExposedMethod;
 import org.python.expose.ExposedNew;
@@ -46,7 +43,7 @@
 
     @ExposedNew
     public static PyObject complex_new(PyNewWrapper new_, boolean init, PyType subtype,
-                                       PyObject[] args, String[] keywords) {
+            PyObject[] args, String[] keywords) {
         ArgParser ap = new ArgParser("complex", args, keywords, "real", "imag");
         PyObject real = ap.getPyObject(0, Py.Zero);
         PyObject imag = ap.getPyObject(1, null);
@@ -54,14 +51,12 @@
         // Special-case for single argument that is already complex
         if (real.getType() == TYPE && new_.for_type == subtype && imag == null) {
             return real;
-        }
-        if (real instanceof PyString) {
+        } else if (real instanceof PyString) {
             if (imag != null) {
                 throw Py.TypeError("complex() can't take second arg if first is a string");
             }
             return real.__complex__();
-        }
-        if (imag != null && imag instanceof PyString) {
+        } else if (imag != null && imag instanceof PyString) {
             throw Py.TypeError("complex() second arg can't be a string");
         }
 
@@ -79,7 +74,7 @@
         PyComplex complexImag;
         PyFloat toFloat = null;
         if (real instanceof PyComplex) {
-            complexReal = (PyComplex) real;
+            complexReal = (PyComplex)real;
         } else {
             try {
                 toFloat = real.__float__();
@@ -96,7 +91,7 @@
         if (imag == null) {
             complexImag = new PyComplex(0.0);
         } else if (imag instanceof PyComplex) {
-            complexImag = (PyComplex) imag;
+            complexImag = (PyComplex)imag;
         } else {
             toFloat = null;
             try {
@@ -129,7 +124,7 @@
 
     public static String toString(double value) {
         if (value == Math.floor(value) && value <= Long.MAX_VALUE && value >= Long.MIN_VALUE) {
-            return Long.toString((long) value);
+            return Long.toString((long)value);
         } else {
             return Double.toString(value);
         }
@@ -164,7 +159,7 @@
             return new PyFloat(real).hashCode();
         } else {
             long v = Double.doubleToLongBits(real) ^ Double.doubleToLongBits(imag);
-            return (int) v ^ (int) (v >> 32);
+            return (int)v ^ (int)(v >> 32);
         }
     }
 
@@ -282,21 +277,18 @@
     }
 
     /**
-     * Coercion logic for complex. Implemented as a final method to avoid
-     * invocation of virtual methods from the exposed coerce.
+     * Coercion logic for complex. Implemented as a final method to avoid invocation of virtual
+     * methods from the exposed coerce.
      */
     final PyObject complex___coerce_ex__(PyObject other) {
         if (other instanceof PyComplex) {
             return other;
-        }
-        if (other instanceof PyFloat) {
-            return new PyComplex(((PyFloat) other).getValue(), 0);
-        }
-        if (other instanceof PyInteger) {
-            return new PyComplex(((PyInteger) other).getValue(), 0);
-        }
-        if (other instanceof PyLong) {
-            return new PyComplex(((PyLong) other).doubleValue(), 0);
+        } else if (other instanceof PyFloat) {
+            return new PyComplex(((PyFloat)other).getValue(), 0);
+        } else if (other instanceof PyInteger) {
+            return new PyComplex(((PyInteger)other).getValue(), 0);
+        } else if (other instanceof PyLong) {
+            return new PyComplex(((PyLong)other).doubleValue(), 0);
         }
         return Py.None;
     }
@@ -308,16 +300,13 @@
 
     private final PyComplex coerce(PyObject other) {
         if (other instanceof PyComplex) {
-            return (PyComplex) other;
-        }
-        if (other instanceof PyFloat) {
-            return new PyComplex(((PyFloat) other).getValue(), 0);
-        }
-        if (other instanceof PyInteger) {
-            return new PyComplex(((PyInteger) other).getValue(), 0);
-        }
-        if (other instanceof PyLong) {
-            return new PyComplex(((PyLong) other).doubleValue(), 0);
+            return (PyComplex)other;
+        } else if (other instanceof PyFloat) {
+            return new PyComplex(((PyFloat)other).getValue(), 0);
+        } else if (other instanceof PyInteger) {
+            return new PyComplex(((PyInteger)other).getValue(), 0);
+        } else if (other instanceof PyLong) {
+            return new PyComplex(((PyLong)other).doubleValue(), 0);
         }
         throw Py.TypeError("xxx");
     }
@@ -377,8 +366,8 @@
     }
 
     private final static PyObject _mul(PyComplex o1, PyComplex o2) {
-        return new PyComplex(o1.real * o2.real - o1.imag * o2.imag,
-                             o1.real * o2.imag + o1.imag * o2.real);
+        return new PyComplex(o1.real * o2.real - o1.imag * o2.imag, //
+                o1.real * o2.imag + o1.imag * o2.real);
     }
 
     @Override
@@ -417,14 +406,14 @@
             }
             double ratio = b.imag / b.real;
             double denom = b.real + b.imag * ratio;
-            return new PyComplex((a.real + a.imag * ratio) / denom,
-                                 (a.imag - a.real * ratio) / denom);
+            return new PyComplex((a.real + a.imag * ratio) / denom, //
+                    (a.imag - a.real * ratio) / denom);
         } else {
             /* divide tops and bottom by b.imag */
             double ratio = b.real / b.imag;
             double denom = b.real * ratio + b.imag;
-            return new PyComplex((a.real * ratio + a.imag) / denom,
-                                 (a.imag * ratio - a.real) / denom);
+            return new PyComplex((a.real * ratio + a.imag) / denom, //
+                    (a.imag * ratio - a.real) / denom);
         }
     }
 
@@ -437,8 +426,7 @@
     final PyObject complex___div__(PyObject right) {
         if (!canCoerce(right)) {
             return null;
-        }
-        if (Options.division_warning >= 2) {
+        } else if (Options.division_warning >= 2) {
             Py.warning(Py.DeprecationWarning, "classic complex division");
         }
         return _div(this, coerce(right));
@@ -453,8 +441,7 @@
     final PyObject complex___rdiv__(PyObject left) {
         if (!canCoerce(left)) {
             return null;
-        }
-        if (Options.division_warning >= 2) {
+        } else if (Options.division_warning >= 2) {
             Py.warning(Py.DeprecationWarning, "classic complex division");
         }
         return _div(coerce(left), this);
@@ -550,7 +537,7 @@
 
     private static PyObject _mod(PyComplex value, PyComplex right) {
         Py.warning(Py.DeprecationWarning, "complex divmod(), // and % are deprecated");
-        PyComplex z = (PyComplex) _div(value, right);
+        PyComplex z = (PyComplex)_div(value, right);
 
         z.real = Math.floor(z.real);
         z.imag = 0.0;
@@ -586,7 +573,7 @@
 
     private static PyObject _divmod(PyComplex value, PyComplex right) {
         Py.warning(Py.DeprecationWarning, "complex divmod(), // and % are deprecated");
-        PyComplex z = (PyComplex) _div(value, right);
+        PyComplex z = (PyComplex)_div(value, right);
 
         z.real = Math.floor(z.real);
         z.imag = 0.0;
@@ -636,12 +623,12 @@
         return complex___pow__(right, modulo);
     }
 
-    @ExposedMethod(type = MethodType.BINARY, defaults = "null", doc = BuiltinDocs.complex___pow___doc)
+    @ExposedMethod(type = MethodType.BINARY, defaults = "null",
+            doc = BuiltinDocs.complex___pow___doc)
     final PyObject complex___pow__(PyObject right, PyObject modulo) {
         if (modulo != null) {
             throw Py.ValueError("complex modulo");
-        }
-        if (!canCoerce(right)) {
+        } else if (!canCoerce(right)) {
             return null;
         }
         return _pow(this, coerce(right));
@@ -677,7 +664,7 @@
         }
 
         // Check for integral powers
-        int iexp = (int) yr;
+        int iexp = (int)yr;
         if (yi == 0 && yr == iexp && iexp >= -128 && iexp <= 128) {
             return ipow(value, iexp);
         }
@@ -764,6 +751,7 @@
         return new PyComplex(real, imag);
     }
 
+    @Override
     public PyComplex conjugate() {
         return complex_conjugate();
     }
@@ -798,13 +786,13 @@
             throw Py.TypeError("__format__ requires str or unicode");
         }
 
-        PyString formatSpecStr = (PyString) formatSpec;
+        PyString formatSpecStr = (PyString)formatSpec;
         String result;
         try {
             String specString = formatSpecStr.getString();
             InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
             switch (spec.type) {
-                case '\0': /* No format code: like 'g', but with at least one decimal. */
+                case '\0': // No format code: like 'g', but with at least one decimal.
                 case 'e':
                 case 'E':
                 case 'f':
@@ -817,8 +805,8 @@
                     break;
                 default:
                     /* unknown */
-                    throw Py.ValueError(String.format("Unknown format code '%c' for object of type 'complex'",
-                                            spec.type));
+                    throw Py.ValueError(String.format(
+                            "Unknown format code '%c' for object of type 'complex'", spec.type));
             }
         } catch (IllegalArgumentException e) {
             throw Py.ValueError(e.getMessage());
@@ -826,7 +814,6 @@
         return formatSpecStr.createInstance(result);
     }
 
-
     @Override
     public boolean isNumberType() {
         return true;
diff --git a/src/org/python/core/PyFloat.java b/src/org/python/core/PyFloat.java
--- a/src/org/python/core/PyFloat.java
+++ b/src/org/python/core/PyFloat.java
@@ -1,23 +1,20 @@
-/*
- * Copyright (c) Corporation for National Research Initiatives
- * Copyright (c) Jython Developers
- */
+// Copyright (c) Corporation for National Research Initiatives
+// Copyright (c) Jython Developers
 package org.python.core;
 
+import java.io.Serializable;
+import java.math.BigDecimal;
+
 import org.python.core.stringlib.Formatter;
 import org.python.core.stringlib.InternalFormatSpec;
 import org.python.core.stringlib.InternalFormatSpecParser;
-import org.python.modules.math;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
 import org.python.expose.ExposedClassMethod;
 import org.python.expose.ExposedGet;
 import org.python.expose.ExposedMethod;
 import org.python.expose.ExposedNew;
 import org.python.expose.ExposedType;
 import org.python.expose.MethodType;
+import org.python.modules.math;
 
 /**
  * A builtin python float.
@@ -47,12 +44,12 @@
     }
 
     public PyFloat(float v) {
-        this((double) v);
+        this((double)v);
     }
 
     @ExposedNew
     public static PyObject float_new(PyNewWrapper new_, boolean init, PyType subtype,
-                                     PyObject[] args, String[] keywords) {
+            PyObject[] args, String[] keywords) {
         ArgParser ap = new ArgParser("float", args, keywords, new String[] {"x"}, 0);
         PyObject x = ap.getPyObject(0, null);
         if (x == null) {
@@ -69,9 +66,9 @@
                 if (e.match(Py.AttributeError)) {
                     // Translate AttributeError to TypeError
                     // XXX: We are using the same message as CPython, even if
-                    //      it is not strictly correct (instances of types
-                    //      that implement the __float__ method are also
-                    //      valid arguments)
+                    // it is not strictly correct (instances of types
+                    // that implement the __float__ method are also
+                    // valid arguments)
                     throw Py.TypeError("float() argument must be a string or a number");
                 }
                 throw e;
@@ -96,9 +93,9 @@
 
     @ExposedClassMethod(doc = BuiltinDocs.float_fromhex_doc)
     public static PyObject float_fromhex(PyType type, PyObject o) {
-        //XXX: I'm sure this could be shortened/simplified, but Double.parseDouble() takes
-        //     non-hex strings and requires the form 0xNUMBERpNUMBER for hex input which
-        //     causes extra complexity here.
+        // XXX: I'm sure this could be shortened/simplified, but Double.parseDouble() takes
+        // non-hex strings and requires the form 0xNUMBERpNUMBER for hex input which
+        // causes extra complexity here.
 
         String message = "invalid hexadecimal floating-point string";
         boolean negative = false;
@@ -108,19 +105,16 @@
 
         if (value.length() == 0) {
             throw Py.ValueError(message);
-        }
-        if (value.equals("nan") || value.equals("-nan") || value.equals("+nan")) {
+        } else if (value.equals("nan") || value.equals("-nan") || value.equals("+nan")) {
             return new PyFloat(Double.NaN);
-        }
-        if (value.equals("inf") ||value.equals("infinity") ||
-                value.equals("+inf") ||value.equals("+infinity")) {
+        } else if (value.equals("inf") || value.equals("infinity") || value.equals("+inf")
+                || value.equals("+infinity")) {
             return new PyFloat(Double.POSITIVE_INFINITY);
-        }
-        if (value.equals("-inf") || value.equals("-infinity")) {
+        } else if (value.equals("-inf") || value.equals("-infinity")) {
             return new PyFloat(Double.NEGATIVE_INFINITY);
         }
 
-        //Strip and record + or -
+        // Strip and record + or -
         if (value.charAt(0) == '-') {
             value = value.substring(1);
             negative = true;
@@ -131,17 +125,17 @@
             throw Py.ValueError(message);
         }
 
-        //Append 0x if not present.
+        // Append 0x if not present.
         if (!value.startsWith("0x") && !value.startsWith("0X")) {
             value = "0x" + value;
         }
 
-        //reattach - if needed.
+        // reattach - if needed.
         if (negative) {
             value = "-" + value;
         }
 
-        //Append p if not present.
+        // Append p if not present.
         if (value.indexOf('p') == -1) {
             value = value + "p0";
         }
@@ -159,7 +153,7 @@
 
     // @ExposedClassMethod(doc = BuiltinDocs.float_hex_doc)
     // public static PyObject float_hex(PyType type, double value) {
-    //     return new PyString(Double.toHexString(value));
+    // return new PyString(Double.toHexString(value));
     // }
 
     private String pyHexString(Double f) {
@@ -167,25 +161,31 @@
         // the most efficient, but we don't expect this to be a hot
         // spot in our code either
         String java_hex = Double.toHexString(getValue());
-        if (java_hex.equals("Infinity")) return "inf";
-        if (java_hex.equals("-Infinity")) return "-inf";
-        if (java_hex.equals("NaN")) return "nan";
-        if (java_hex.equals("0x0.0p0")) return "0x0.0p+0";
-        if (java_hex.equals("-0x0.0p0")) return "-0x0.0p+0";
+        if (java_hex.equals("Infinity")) {
+            return "inf";
+        } else if (java_hex.equals("-Infinity")) {
+            return "-inf";
+        } else if (java_hex.equals("NaN")) {
+            return "nan";
+        } else if (java_hex.equals("0x0.0p0")) {
+            return "0x0.0p+0";
+        } else if (java_hex.equals("-0x0.0p0")) {
+            return "-0x0.0p+0";
+        }
 
-	// replace hex rep of MpE to conform with Python such that
-        //   1. M is padded to 16 digits (ignoring a leading -)
-        //   2. Mp+E if E>=0
+        // replace hex rep of MpE to conform with Python such that
+        // 1. M is padded to 16 digits (ignoring a leading -)
+        // 2. Mp+E if E>=0
         // example: result of 42.0.hex() is translated from
-        //   0x1.5p5 to 0x1.5000000000000p+5
+        // 0x1.5p5 to 0x1.5000000000000p+5
         int len = java_hex.length();
         boolean start_exponent = false;
         StringBuilder py_hex = new StringBuilder(len + 1);
         int padding = f > 0 ? 17 : 18;
-        for (int i=0; i < len; i++) {
+        for (int i = 0; i < len; i++) {
             char c = java_hex.charAt(i);
             if (c == 'p') {
-                for (int pad=i; pad < padding; pad++) {
+                for (int pad = i; pad < padding; pad++) {
                     py_hex.append('0');
                 }
                 start_exponent = true;
@@ -194,9 +194,9 @@
                     py_hex.append('+');
                 }
                 start_exponent = false;
-	    }
+            }
             py_hex.append(c);
-	}
+        }
         return py_hex.toString();
     }
 
@@ -274,23 +274,22 @@
         double value = getValue();
         if (Double.isInfinite(value)) {
             return value < 0 ? -271828 : 314159;
-        }
-        if (Double.isNaN(value)) {
+        } else if (Double.isNaN(value)) {
             return 0;
         }
-        
+
         double intPart = Math.floor(value);
         double fractPart = value - intPart;
 
         if (fractPart == 0) {
             if (intPart <= Integer.MAX_VALUE && intPart >= Integer.MIN_VALUE) {
-                return (int) value;
+                return (int)value;
             } else {
                 return __long__().hashCode();
             }
         } else {
             long v = Double.doubleToLongBits(getValue());
-            return (int) v ^ (int) (v >> 32);
+            return (int)v ^ (int)(v >> 32);
         }
     }
 
@@ -307,10 +306,9 @@
     @Override
     public Object __tojava__(Class<?> c) {
         if (c == Double.TYPE || c == Number.class || c == Double.class || c == Object.class
-            || c == Serializable.class) {
+                || c == Serializable.class) {
             return new Double(getValue());
-        }
-        if (c == Float.TYPE || c == Float.class) {
+        } else if (c == Float.TYPE || c == Float.class) {
             return new Float(getValue());
         }
         return super.__tojava__(c);
@@ -345,7 +343,7 @@
 
     @Override
     public PyObject __ge__(PyObject other) {
-        //NaN >= anything is always false.
+        // NaN >= anything is always false.
         if (Double.isNaN(getValue())) {
             return Py.False;
         }
@@ -354,7 +352,7 @@
 
     @Override
     public PyObject __lt__(PyObject other) {
-        //NaN < anything is always false.
+        // NaN < anything is always false.
         if (Double.isNaN(getValue())) {
             return Py.False;
         }
@@ -363,7 +361,7 @@
 
     @Override
     public PyObject __le__(PyObject other) {
-        //NaN >= anything is always false.
+        // NaN >= anything is always false.
         if (Double.isNaN(getValue())) {
             return Py.False;
         }
@@ -382,7 +380,7 @@
         double j;
 
         if (other instanceof PyFloat) {
-            j = ((PyFloat) other).getValue();
+            j = ((PyFloat)other).getValue();
         } else if (!isFinite()) {
             // we're infinity: our magnitude exceeds any finite
             // integer, so it doesn't matter which int we compare i
@@ -393,10 +391,10 @@
                 return -2;
             }
         } else if (other instanceof PyInteger) {
-            j = ((PyInteger) other).getValue();
+            j = ((PyInteger)other).getValue();
         } else if (other instanceof PyLong) {
             BigDecimal v = new BigDecimal(getValue());
-            BigDecimal w = new BigDecimal(((PyLong) other).getValue());
+            BigDecimal w = new BigDecimal(((PyLong)other).getValue());
             return v.compareTo(w);
         } else {
             return -2;
@@ -425,21 +423,18 @@
     }
 
     /**
-     * Coercion logic for float. Implemented as a final method to avoid
-     * invocation of virtual methods from the exposed coerce.
+     * Coercion logic for float. Implemented as a final method to avoid invocation of virtual
+     * methods from the exposed coerce.
      */
     final Object float___coerce_ex__(PyObject other) {
         if (other instanceof PyFloat) {
             return other;
+        } else if (other instanceof PyInteger) {
+            return new PyFloat((double)((PyInteger)other).getValue());
+        } else if (other instanceof PyLong) {
+            return new PyFloat(((PyLong)other).doubleValue());
         } else {
-            if (other instanceof PyInteger) {
-                return new PyFloat((double) ((PyInteger) other).getValue());
-            }
-            if (other instanceof PyLong) {
-                return new PyFloat(((PyLong) other).doubleValue());
-            } else {
-                return Py.None;
-            }
+            return Py.None;
         }
     }
 
@@ -449,11 +444,11 @@
 
     private static double coerce(PyObject other) {
         if (other instanceof PyFloat) {
-            return ((PyFloat) other).getValue();
+            return ((PyFloat)other).getValue();
         } else if (other instanceof PyInteger) {
-            return ((PyInteger) other).getValue();
+            return ((PyInteger)other).getValue();
         } else if (other instanceof PyLong) {
-            return ((PyLong) other).doubleValue();
+            return ((PyLong)other).doubleValue();
         } else {
             throw Py.TypeError("xxx");
         }
@@ -544,8 +539,7 @@
     final PyObject float___div__(PyObject right) {
         if (!canCoerce(right)) {
             return null;
-        }
-        if (Options.division_warning >= 2) {
+        } else if (Options.division_warning >= 2) {
             Py.warning(Py.DeprecationWarning, "classic float division");
         }
 
@@ -565,8 +559,7 @@
     final PyObject float___rdiv__(PyObject left) {
         if (!canCoerce(left)) {
             return null;
-        }
-        if (Options.division_warning >= 2) {
+        } else if (Options.division_warning >= 2) {
             Py.warning(Py.DeprecationWarning, "classic float division");
         }
 
@@ -667,7 +660,7 @@
             return null;
         }
         double rightv = coerce(right);
-        return new PyFloat(modulo(getValue(),rightv));
+        return new PyFloat(modulo(getValue(), rightv));
     }
 
     @Override
@@ -729,18 +722,16 @@
         return float___pow__(right, modulo);
     }
 
-    @ExposedMethod(type = MethodType.BINARY, defaults = "null",
-                   doc = BuiltinDocs.float___pow___doc)
+    @ExposedMethod(type = MethodType.BINARY, defaults = "null", //
+            doc = BuiltinDocs.float___pow___doc)
     final PyObject float___pow__(PyObject right, PyObject modulo) {
         if (!canCoerce(right)) {
             return null;
-        }
-
-        if (modulo != null) {
+        } else if (modulo != null) {
             throw Py.TypeError("pow() 3rd argument not allowed unless all arguments are integers");
         }
 
-        return _pow( getValue(), coerce(right), modulo);
+        return _pow(getValue(), coerce(right), modulo);
     }
 
     @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rpow___doc)
@@ -769,8 +760,7 @@
         if (value == 0.0) {
             if (iw < 0.0) {
                 throw Py.ZeroDivisionError("0.0 cannot be raised to a negative power");
-            }
-            if (Double.isNaN(iw)) {
+            } else if (Double.isNaN(iw)) {
                 return new PyFloat(Double.NaN);
             }
             return new PyFloat(0);
@@ -838,7 +828,7 @@
     @ExposedMethod(doc = BuiltinDocs.float___int___doc)
     final PyObject float___int__() {
         if (getValue() <= Integer.MAX_VALUE && getValue() >= Integer.MIN_VALUE) {
-            return new PyInteger((int) getValue());
+            return new PyInteger((int)getValue());
         }
         return __long__();
     }
@@ -902,7 +892,7 @@
     @ExposedMethod(doc = BuiltinDocs.float_is_integer_doc)
     final boolean float_is_integer() {
         if (Double.isInfinite(value)) {
-            return false; 
+            return false;
         }
         return Math.floor(value) == value;
     }
@@ -937,16 +927,16 @@
             throw Py.TypeError("__format__ requires str or unicode");
         }
 
-        PyString formatSpecStr = (PyString) formatSpec;
+        PyString formatSpecStr = (PyString)formatSpec;
         String result;
         try {
             String specString = formatSpecStr.getString();
             InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
-            if (spec.type == '\0'){
+            if (spec.type == '\0') {
                 return (Py.newFloat(d)).__str__();
             }
             switch (spec.type) {
-                case '\0': /* No format code: like 'g', but with at least one decimal. */
+                case '\0': // No format code: like 'g', but with at least one decimal.
                 case 'e':
                 case 'E':
                 case 'f':
@@ -959,8 +949,8 @@
                     break;
                 default:
                     /* unknown */
-                    throw Py.ValueError(String.format("Unknown format code '%c' for object of type 'float'",
-                                            spec.type));
+                    throw Py.ValueError(String.format(
+                            "Unknown format code '%c' for object of type 'float'", spec.type));
             }
         } catch (IllegalArgumentException e) {
             throw Py.ValueError(e.getMessage());
@@ -979,14 +969,15 @@
         PyTuple frexp = math.frexp(value);
         double float_part = ((Double)frexp.get(0)).doubleValue();
         int exponent = ((Integer)frexp.get(1)).intValue();
-        for (int i=0; i<300 && float_part != Math.floor(float_part); i++) {
+        for (int i = 0; i < 300 && float_part != Math.floor(float_part); i++) {
             float_part *= 2.0;
             exponent--;
         }
-        /* self == float_part * 2**exponent exactly and float_part is integral.
-           If FLT_RADIX != 2, the 300 steps may leave a tiny fractional part
-           to be truncated by PyLong_FromDouble(). */
-        
+        /*
+         * self == float_part * 2**exponent exactly and float_part is integral. If FLT_RADIX != 2,
+         * the 300 steps may leave a tiny fractional part to be truncated by PyLong_FromDouble().
+         */
+
         PyLong numerator = new PyLong(float_part);
         PyLong denominator = new PyLong(1);
         PyLong py_exponent = new PyLong(Math.abs(exponent));
@@ -1013,9 +1004,7 @@
     // but this is what Python demands
     public enum Format {
 
-        UNKNOWN("unknown"),
-        BE("IEEE, big-endian"),
-        LE("IEEE, little-endian");
+        UNKNOWN("unknown"), BE("IEEE, big-endian"), LE("IEEE, little-endian");
 
         private final String format;
 
@@ -1027,6 +1016,7 @@
             return format;
         }
     }
+
     // subset of IEEE-754, the JVM is big-endian
     public static volatile Format double_format = Format.BE;
     public static volatile Format float_format = Format.BE;
@@ -1050,14 +1040,14 @@
         }
         if (Format.LE.format().equals(format)) {
             throw Py.ValueError(String.format("can only set %s format to 'unknown' or the "
-                                              + "detected platform value", typestr));
+                    + "detected platform value", typestr));
         } else if (Format.BE.format().equals(format)) {
             new_format = Format.BE;
         } else if (Format.UNKNOWN.format().equals(format)) {
             new_format = Format.UNKNOWN;
         } else {
-            throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " +
-                                "'IEEE, little-endian' or 'IEEE, big-endian'");
+            throw Py.ValueError("__setformat__() argument 2 must be 'unknown', "
+                    + "'IEEE, little-endian' or 'IEEE, big-endian'");
         }
         if (new_format != null) {
             if ("double".equals(typestr)) {

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list