Commits

Frank Wierzbicki committed 7bd335f

More inf string values, getIndex in ArgParser.

Now allowing +inf and infinity for spelling infinity.
Added getIndex to ArgParser for getting an index. Used in round() builtin.

Comments (0)

Files changed (3)

src/org/python/core/ArgParser.java

     }
 
     /**
+     * Return an required argument as an index.
+     * 
+     * @param pos The position of the argument. First argument is numbered 0.
+     */
+    public int getIndex(int pos) {
+        PyObject value = getRequiredArg(pos);
+        return value.asIndex();
+    }
+
+    /**
+     * Return an optional argument as an index.
+     * 
+     * @param pos The position of the argument. First argument is numbered 0.
+     */
+    public int getIndex(int pos, int def) {
+        PyObject value = getOptionalArg(pos);
+        if (value == null) {
+            return def;
+        }
+        return value.asIndex();
+    }
+
+    /**
      * Return a required argument as a PyObject.
      * 
      * @param pos The position of the argument. First argument is numbered 0.

src/org/python/core/PyString.java

             String lowSval = sval.toLowerCase();
             if (lowSval.equals("nan")) return Double.NaN;
             else if (lowSval.equals("inf")) return Double.POSITIVE_INFINITY;
+            else if (lowSval.equals("+inf")) return Double.POSITIVE_INFINITY;
             else if (lowSval.equals("-inf")) return Double.NEGATIVE_INFINITY;
-            
+            else if (lowSval.equals("infinity")) return Double.POSITIVE_INFINITY;
+            else if (lowSval.equals("+infinity")) return Double.POSITIVE_INFINITY;
+            else if (lowSval.equals("-infinity")) return Double.NEGATIVE_INFINITY;
+             
             if (lowSval.endsWith("d") || lowSval.endsWith("f")) {
                 throw new NumberFormatException("format specifiers not allowed");
             }

src/org/python/core/__builtin__.java

     public PyObject __call__(PyObject args[], String kwds[]) {
         ArgParser ap = new ArgParser("round", args, kwds, new String[] {"number", "ndigits"}, 0);
         PyObject number = ap.getPyObject(0);
-        int ndigits = ap.getInt(1, 0);
+        int ndigits = ap.getIndex(1, 0);
         return round(number.asDouble(), ndigits);
     }