The global method parseFloat, as per ECMA-262 15.1.2.3.

@param args the arguments to parseFloat, ignoring args[>=1]
965585
static Object js_parseFloat(Object[] args)
    {
        if (args.length < 1)
            return ScriptRuntime.NaNobj;

        String s = ScriptRuntime.toString(args[0]);
        int len = s.length();
        int start = 0;
        // Scan forward to skip whitespace
        char c;
        for (;;) {
            if (start == len) {
                return ScriptRuntime.NaNobj;
            }
            c = s.charAt(start);
            if (!ScriptRuntime.isStrWhiteSpaceChar(c)) {
                break;
            }
            ++start;
        }

        int i = start;
        if (c == '+' || c == '-') {
            ++i;
            if (i == len) {
                return ScriptRuntime.NaNobj;
            }
            c = s.charAt(i);
        }

        if (c == 'I') {
            // check for "Infinity"
            if (i+8 <= len && s.regionMatches(i, "Infinity", 0, 8)) {
                double d;
                if (s.charAt(start) == '-') {
                    d = Double.NEGATIVE_INFINITY;
                } else {
                    d = Double.POSITIVE_INFINITY;
                }
                return ScriptRuntime.wrapNumber(d);
            }
            return ScriptRuntime.NaNobj;
        }

        // Find the end of the legal bit
        int decimal = -1;
        int exponent = -1;
        boolean exponentValid = false;
        for (; i < len; i++) {
            switch (s.charAt(i)) {
              case '.':
                if (decimal != -1) // Only allow a single decimal point.
                    break;
                decimal = i;
                continue;

              case 'e':
              case 'E':
                if (exponent != -1) {
                    break;
                } else if (i == len - 1) {
                    break;
                }
                exponent = i;
                continue;

              case '+':
              case '-':
                 // Only allow '+' or '-' after 'e' or 'E'
                if (exponent != i-1) {
                    break;
                } else if (i == len - 1) {
                    --i;
                    break;
                }
                continue;

              case '0': case '1': case '2': case '3': case '4':
              case '5': case '6': case '7': case '8': case '9':
                if (exponent != -1) {
                    exponentValid = true;
                }
                continue;

              default:
                break;
            }
            break;
        }
        if (exponent != -1 && !exponentValid) {
            i = exponent;
        }
        s = s.substring(start, i);
        try {
            return Double.valueOf(s);
        }
        catch (NumberFormatException ex) {
            return ScriptRuntime.NaNobj;
        }
    }
132716
@Override
    public boolean parseArguments(final PrintStream messageStream, final String[] args) {
        this.argv = args;
        this.messageStream = messageStream;
        if (prefix.isEmpty()) {
            commandLine = callerOptions.getClass().getSimpleName();
        }
        for (int i = 0; i < args.length; ++i) {
            final String arg = args[i];
            if (arg.equals("-h") || arg.equals("--help")) {
                messageStream.append(usage(false, true));
                return false;
            }
            if (arg.equals("-H") || arg.equals("--stdhelp")) {
                messageStream.append(usage(true, true));
                return false;
            }

            if (arg.equals("--version")) {
                messageStream.println(getVersion());
                return false;
            }

            final String[] pair = arg.split("=", 2);
            if (pair.length == 2) {
                if (pair[1].isEmpty() && i < args.length - 1) {
                    pair[1] = args[++i];
                }
                if (!parseOption(pair[0], pair[1], false)) {
                    messageStream.println();
                    messageStream.append(usage(true, true));
                    return false;
                }
            } else if (!parsePositionalArgument(arg)) {
                messageStream.println();
                messageStream.append(usage(false, true));
                return false;
            }
        }
        if (!checkNumArguments()) {
            messageStream.println();
            messageStream.append(usage(false, true));
            return false;
        }

        return true;
    }
685572
public static CliArguments parse(String[] args) {
        CliArguments arguments = new CliArguments();
        if (args != null) {
            CmdLineParser parser = new CmdLineParser(arguments);
            try {
                parser.parseArgument(args);
            } catch (CmdLineException e) {
                // ignore
            }

            arguments.usageMode = false;
            for (String arg : args) {
                for (int i = 0; i < USAGE_TOKENS.length; i++) {
                    String usageToken = USAGE_TOKENS[i];
                    if (usageToken.equalsIgnoreCase(arg)) {
                        arguments.usageMode = true;
                        break;
                    }
                }
            }
        }
        return arguments;
    }
415909
private NumberFormat parseFormatter(Context context, Arguments args)
    {
        final String format = args.get(FORMAT_PARAM_NAME);
        final Locale locale = context.get(LOCALE);
        if (format != null)
        {
            return new DecimalFormat(format, DecimalFormatSymbols.getInstance(locale));
        }

        final Mode mode = Mode.loadFromContext(args, this.defaultMode);
        if (Mode.INTEGER.equals(mode))
        {
            return NumberFormat.getIntegerInstance(locale);
        }
        if (Mode.CURRENCY.equals(mode))
        {
            return NumberFormat.getCurrencyInstance(locale);
        }
        if (Mode.PERCENT.equals(mode))
        {
            return NumberFormat.getPercentInstance(locale);
        }
        return NumberFormat.getInstance(locale);
    }
292839
public String[] parse(String[] args) throws ArgException {

    List<String> nonOptions = new ArrayList<>();
    // If true, then "--" has been seen and any argument starting with "-"
    // is processed as an ordinary argument, not as an option.
    boolean ignoreOptions = false;

    // Loop through each argument
    String tail = "";
    String arg;
    for (int ii = 0; ii < args.length; ) {
      // If there was a ',' separator in previous arg, use the tail as
      // current arg; otherwise, fetch the next arg from args list.
      if (tail.length() > 0) {
        arg = tail;
        tail = "";
      } else {
        arg = args[ii];
      }

      if (arg.equals("--")) {
        ignoreOptions = true;
      } else if ((arg.startsWith("--") || arg.startsWith("-")) && !ignoreOptions) {
        String argName;
        String argValue;

        // Allow ',' as an argument separator to get around
        // some command line quoting problems.  (markro)
        int splitPos = arg.indexOf(",-");
        if (splitPos == 0) {
          // Just discard the ',' if ",-" occurs at begining of string
          arg = arg.substring(1);
          splitPos = arg.indexOf(",-");
        }
        if (splitPos > 0) {
          tail = arg.substring(splitPos + 1);
          arg = arg.substring(0, splitPos);
        }

        int eqPos = arg.indexOf('=');
        if (eqPos == -1) {
          argName = arg;
          argValue = null;
        } else {
          argName = arg.substring(0, eqPos);
          argValue = arg.substring(eqPos + 1);
        }
        OptionInfo oi = nameMap.get(argName);
        if (oi == null) {
          StringBuilder msg = new StringBuilder();
          msg.append(String.format("unknown option name '%s' in arg '%s'", argName, arg));
          if (false) { // for debugging
            msg.append("; known options:");
            for (String optionName : sortedKeySet(nameMap)) {
              msg.append(" ");
              msg.append(optionName);
            }
          }
          throw new ArgException(msg.toString());
        }
        if (oi.argumentRequired() && (argValue == null)) {
          ii++;
          if (ii >= args.length) {
            throw new ArgException("option %s requires an argument", arg);
          }
          argValue = args[ii];
        }
        // System.out.printf ("argName = '%s', argValue='%s'%n", argName,
        //                    argValue);
        setArg(oi, argName, argValue);
      } else { // not an option
        if (!parseAfterArg) {
          ignoreOptions = true;
        }
        nonOptions.add(arg);
      }

      // If no ',' tail, advance to next args option
      if (tail.length() == 0) {
        ii++;
      }
    }
    String[] result = nonOptions.toArray(new String[nonOptions.size()]);
    return result;
  }
696995
def _parseIntegerArgument(args, key, defaultValue):
    
    ret = defaultValue
    try:
        if key in args:
            try:
                ret = int(args[key])
            except ValueError:
                raise exceptions.BadRequestIntegerException(key, args[key])
    except TypeError:
        raise Exception((key, args))
    return ret
594372
private static String convertArgs(String[] args)
    {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < args.length; i++)
        {
            result.append(args[i]);
            if (i < args.length - 1)
            {
                result.append(' ');
            }
        }
        return result.toString().toUpperCase();
    }
1212443
public static void main(String[] args) {
    if (args.length == 0) {
      System.err.println("Usage: java edu.stanford.nlp.math.SloppyMath " + "[-logAdd|-fishers k n r m|-binomial r n p");
    } else if (args[0].equals("-logAdd")) {
      System.out.println("Log adds of neg infinity numbers, etc.");
      System.out.println("(logs) -Inf + -Inf = " + logAdd(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY));
      System.out.println("(logs) -Inf + -7 = " + logAdd(Double.NEGATIVE_INFINITY, -7.0));
      System.out.println("(logs) -7 + -Inf = " + logAdd(-7.0, Double.NEGATIVE_INFINITY));
      System.out.println("(logs) -50 + -7 = " + logAdd(-50.0, -7.0));
      System.out.println("(logs) -11 + -7 = " + logAdd(-11.0, -7.0));
      System.out.println("(logs) -7 + -11 = " + logAdd(-7.0, -11.0));
      System.out.println("real 1/2 + 1/2 = " + logAdd(Math.log(0.5), Math.log(0.5)));
    } else if (args[0].equals("-fishers")) {
      int k = Integer.parseInt(args[1]);
      int n = Integer.parseInt(args[2]);
      int r = Integer.parseInt(args[3]);
      int m = Integer.parseInt(args[4]);
      double ans = SloppyMath.hypergeometric(k, n, r, m);
      System.out.println("hypg(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans);
      ans = SloppyMath.oneTailedFishersExact(k, n, r, m);
      System.out.println("1-tailed Fisher's exact(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans);
      double ansChi = SloppyMath.chiSquare2by2(k, n, r, m);
      System.out.println("chiSquare(" + k + "; " + n + ", " + r + ", " + m + ") = " + ansChi);

      System.out.println("Swapping arguments should give same hypg:");
      ans = SloppyMath.hypergeometric(k, n, r, m);
      System.out.println("hypg(" + k + "; " + n + ", " + m + ", " + r + ") = " + ans);
      int othrow = n - m;
      int othcol = n - r;
      int cell12 = m - k;
      int cell21 = r - k;
      int cell22 = othrow - (r - k);
      ans = SloppyMath.hypergeometric(cell12, n, othcol, m);
      System.out.println("hypg(" + cell12 + "; " + n + ", " + othcol + ", " + m + ") = " + ans);
      ans = SloppyMath.hypergeometric(cell21, n, r, othrow);
      System.out.println("hypg(" + cell21 + "; " + n + ", " + r + ", " + othrow + ") = " + ans);
      ans = SloppyMath.hypergeometric(cell22, n, othcol, othrow);
      System.out.println("hypg(" + cell22 + "; " + n + ", " + othcol + ", " + othrow + ") = " + ans);
    } else if (args[0].equals("-binomial")) {
      int k = Integer.parseInt(args[1]);
      int n = Integer.parseInt(args[2]);
      double p = Double.parseDouble(args[3]);
      double ans = SloppyMath.exactBinomial(k, n, p);
      System.out.println("Binomial p(X >= " + k + "; " + n + ", " + p + ") = " + ans);
    } else {
      System.err.println("Unknown option: " + args[0]);
    }
  }
1178268
private void oneArg(String[] args, int index) {
        if ((index + 1) < args.length) {
            setOption(args[index], args[index+1]);
        } else {
            usageError("main.requires_argument", args[index]);
        }
    }
587064
@Override
	public double call(FunctionCall call, double arg) {

		// set all the parameters
		JexlContext context = new MapContext();
		call.parameterNames().forEach(parameterName -> 
				context.set(parameterName, call.getParameter(parameterName).doubleValue()));

		// set the argument value
		context.set(call.getFunction().getArgumentName(), arg);

		// find the appropriate range first
		Expression funcBody = null;
		for (Range r : ranges) {
			boolean fromMatch;
			boolean toMatch;

			Double fromValue = 0.0;
			if (r.haveFromExpr()) {
				fromValue = (Double) r.getFromExpr().evaluate(context);
				fromMatch = arg >= fromValue;
			} else {
				fromMatch = true;
			}

			Double toValue = 0.0;
			if (r.haveToExpr()) {
				toValue = (Double) r.getToExpr().evaluate(context);
				toMatch = arg <= toValue;
			} else {
				toMatch = fromMatch;
			}

			if (fromMatch && toMatch) {
				String from = r.getFromExpr() == null ? "<" : r.getFromExpr().getExpression();
				String to = r.getToExpr() == null ? ">" : r.getToExpr().getExpression();
				System.out.print("match " + from + "->" + fromValue + " .. " + to + "->" + toValue + " for " + arg);
				funcBody = r.getFuncBody();
				break;
			}
		}
		// now evaluate the function body
		if (funcBody == null) {
			throw new FuzzerException(call.getFunction().getName() + ": no range found for " + arg);
		}
		Object result = funcBody.evaluate(context);
		System.out.println(" "+funcBody.getExpression()+" -> "+result);
		if (result instanceof Number) {
			return ((Number) result).doubleValue();
		} else {
			throw new FuzzerException(getName() + ": unable to evaluate to number '" + funcBody.getExpression() + "'");
		}
	}
486866
public static BigDecimal sum(EvaluationContext ctx, Object... args) {
        if (args.length == 0) {
            throw new RuntimeException("Wrong number of arguments");
        }

        BigDecimal result = BigDecimal.ZERO;
        for (Object arg : args) {
            result = result.add(Conversions.toDecimal(arg, ctx));
        }
        return result;
    }
608046
private int init(String[] args) {
    try {
      for (int i = 0; i < args.length; i++) { // parse command line
        if (args[i].equals("-maxDepth")) {
          maxDepth = Integer.parseInt(args[++i]);
          if (maxDepth<1) {
            System.err.println("maxDepth must be positive: " + maxDepth);
            return -1;
          }
        } else if (args[i].equals("-minWidth")) {
          minWidth = Integer.parseInt(args[++i]);
          if (minWidth<0) {
            System.err.println("minWidth must be positive: " + minWidth);
            return -1;
          }
        } else if (args[i].equals("-maxWidth")) {
          maxWidth = Integer.parseInt(args[++i]);
        } else if (args[i].equals("-numOfFiles")) {
          numOfFiles = Integer.parseInt(args[++i]);
          if (numOfFiles<1) {
            System.err.println("NumOfFiles must be positive: " + numOfFiles);
            return -1;
          }
        } else if (args[i].equals("-avgFileSize")) {
          avgFileSize = Double.parseDouble(args[++i]);
          if (avgFileSize<=0) {
            System.err.println("AvgFileSize must be positive: " + avgFileSize);
            return -1;
          }
        } else if (args[i].equals("-outDir")) {
          outDir = new File(args[++i]);
        } else if (args[i].equals("-seed")) {
          r = new Random(Long.parseLong(args[++i]));
        } else {
          System.err.println(USAGE);
          ToolRunner.printGenericCommandUsage(System.err);
          return -1;
        }
      }
    } catch (NumberFormatException e) {
      System.err.println("Illegal parameter: " + e.getLocalizedMessage());
      System.err.println(USAGE);
      return -1;
    }

    if (maxWidth < minWidth) {
      System.err.println(
          "maxWidth must be bigger than minWidth: " + maxWidth);
      return -1;
    }

    if (r==null) {
      r = new Random();
    }
    return 0;
  }
619665
private static String parseFormat(List<? extends TargetExpr> args) {
    String numberFormatType = !args.isEmpty() ? args.get(0).getText() : "'" + DEFAULT_FORMAT + "'";

    if (!JS_ARGS_TO_ENUM.containsKey(numberFormatType)) {
      String validKeys = Joiner.on("', '").join(JS_ARGS_TO_ENUM.keySet());
      throw new IllegalArgumentException(
          "First argument to formatNum must be constant, and one of: '" + validKeys + "'.");
    }

    return numberFormatType;
  }
367576
public static void main(String[] args)
    {
        Context cx = Context.enter();
        try {
            // Set version to JavaScript1.2 so that we get object-literal style
            // printing instead of "[object Object]"
            cx.setLanguageVersion(Context.VERSION_1_2);

            // Initialize the standard objects (Object, Function, etc.)
            // This must be done before scripts can be executed.
            Scriptable scope = cx.initStandardObjects();

            // Now we can evaluate a script. Let's create a new object
            // using the object literal notation.
            Object result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}",
                                              "MySource", 1, null);

            Scriptable obj = (Scriptable) scope.get("obj", scope);

            // Should print "obj == result" (Since the result of an assignment
            // expression is the value that was assigned)
            System.out.println("obj " + (obj == result ? "==" : "!=") +
                               " result");

            // Should print "obj.a == 1"
            System.out.println("obj.a == " + obj.get("a", obj));

            Scriptable b = (Scriptable) obj.get("b", obj);

            // Should print "obj.b[0] == x"
            System.out.println("obj.b[0] == " + b.get(0, b));

            // Should print "obj.b[1] == y"
            System.out.println("obj.b[1] == " + b.get(1, b));

            // Should print {a:1, b:["x", "y"]}
            Function fn = (Function) ScriptableObject.getProperty(obj, "toString");
            System.out.println(fn.call(cx, scope, obj, new Object[0]));
        } finally {
            Context.exit();
        }
    }
276581
function ConstantAggregateExpression(number) {
    if(!Number.isFinite(number))
        this.number = parseFloat(number);
    else
        this.number = number;
}
1118042
public Map<String, String> parseArgs(String[] args) {

        Map<String, String> result = new HashMap<String, String>();
        Set<String> allowedKeys = new HashSet<String>(
            Arrays.asList(PARAM_ADDITIONAL, PARAM_SCRIPT, PARAM_REGISTRY_PORT));
        for (String arg : args) {
            if (arg.startsWith("-")) {
                int eqPos = arg.indexOf("=");
                if (eqPos >= 0) {
                    String key = arg.substring(1, eqPos);
                    if (!allowedKeys.contains(key)) {
                        wrongUsage();
                    }
                    String val = arg.substring(eqPos + 1);
                    result.put(key, val);
                } else {
                    wrongUsage();
                }
            } else {
                wrongUsage();
            }
        }
        return result;
    }
1362923
function castArgument(arg) {
		if (isNumber(arg)) {
			return parseFloat(arg);
		}

		if (helpers.isFraction(arg)) {
			arg = arg.split('/');

			return arg[0] / arg[1];
		}

		if (arg === 'false' || arg === 'true') {
			return arg === 'true';
		}

		return arg.length ? arg : undefined;
	}