Examples of BigDec


Examples of lipstone.joshua.parser.types.BigDec

        (BigDec) parser.run(sections.get(1)).getCar() : new BigDec(parser.getDefaultLogBase())).doubleValue()));
  }
 
  public BigDec sigfigs(ConsCell num) throws ParserException {
    String number = parser.run(num).toString();
    BigDec sigfigs = BigDec.ZERO;
    boolean start = false;
    for (int i = 0; i < number.length(); i++) {
      if (parser.isNumber(number.charAt(i))) {
        if (!start && number.charAt(i) != '0')
          start = true;
        if (start)
          sigfigs = sigfigs.pp();
      }
    }
    return sigfigs;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    while (num.charAt(0) == '0' && num.charAt(1) != '.')
      num = num.substring(1);
    if (num.length() > 1) {
      for (int i = 0; i < num.length(); i++)
        if (parser.isNumber(num.charAt(i)) && num.charAt(i) != '0' && num.charAt(i) != '.') {
          parts[1] = new BigDec(num.indexOf('.') - i - 1).toString();
          break;
        }
      parts[0] = num.substring(0, 1) + "." + num.substring(1).replaceAll("\\Q.\\E", "");
    }
    else
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    }
    return num;
  }
 
  public BigDec phi(ConsCell num) throws ParserException {
    BigDec output = BigDec.ZERO;
    num = parser.run(num);
    ArrayList<ConsCell> factors = parser.getCAS().primeFactor(num).splitOnSeparator();
    String temp = num.toString();
    for (ConsCell factor : factors)
      temp = temp + "*(" + factor.toString() + "-1)";
    temp = temp + "/(";
    for (ConsCell factor : factors)
      temp = temp + factor.toString() + "*";
    temp = temp.substring(0, temp.length() - 1) + ")";
    output = new BigDec(((BigDec) parser.run(parser.preProcess(Tokenizer.tokenizeString(temp))).getCar()).intValue());
    return output;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

  }
 
  public boolean isRelativelyPrime(ConsCell num) throws ParserException {
    num = parser.run(num);
    ArrayList<ConsCell> parts = num.splitOnSeparator();
    BigDec num1 = BigDec.ZERO, num2 = BigDec.ZERO;
    if (parts.get(0).getCarType() != ConsType.NUMBER || parts.get(1).getCarType() != ConsType.NUMBER)
      throw new InvalidOperationException("Both arguments to isRelativelyPrime must be numbers.", this, null, null);
    return isRelativelyPrime(num1, num2);
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

  public ConsCell runOperation(String operation, ConsCell input) throws ParserException {
    int numParams = input.splitOnSeparator().size();
    if (operation.equals("round"))
      return new ConsCell(round(input), ConsType.NUMBER);
    if (operation.equals("ceil"))
      return new ConsCell(new BigDec(Math.ceil(new Double(parser.run(input).toString()))), ConsType.NUMBER);
    if (operation.equals("floor"))
      return new ConsCell(new BigDec(Math.floor(new Double(parser.run(input).toString()))), ConsType.NUMBER);
    if (operation.equals("factorial"))
      return new ConsCell(factorial(input), ConsType.NUMBER);
    if (operation.equals("log"))
      return new ConsCell(log(input), ConsType.NUMBER);
    if (operation.equals("ln"))
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

        continue;
      Matcher m = factorial.matcher((String) current.getCar());
      if (m.matches()) {
        //This line produces the following structure: factorial ([data before !'s] , [number of !'s])
        ConsCell replacement = new ConsCell("factorial", ConsType.IDENTIFIER, new ConsCell(new ConsCell(current.getPreviousConsCell().getCar(), current.getPreviousConsCell().getCarType(),
            new ConsCell(",", ConsType.SEPARATOR, new ConsCell(new BigDec(((String) current.getCar()).length()), ConsType.NUMBER))), ConsType.CONS_CELL));
        if (current.getPreviousConsCell() == input) {
          replacement.getLastConsCell().append(input.getNextConsCell(2));
          input = current = replacement;
        }
        else {
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    this.color = p.color;
    this.diameter = p.diameter;
  }
 
  public BigDec[] getPosition(){
    BigDec output[] = {BigDec.ZERO, BigDec.ZERO};
    output[0] = x;
    output[1] = y;
    return output;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

              break;
          }
          decimal += working;
        }
        if (first)
          input = new ConsCell(new BigDec(number + (dec ? ((double) decimal) / Math.pow(10, ((int) Math.log10(decimal) + 1)) : 0)), ConsType.NUMBER, current);
        else {
          head = head.remove().getPreviousConsCell();
          head.append(new ConsCell(new BigDec(number + (dec ? ((double) decimal) / Math.pow(10, ((int) Math.log10(decimal) + 1)) : 0)), ConsType.NUMBER, current));
        }
        if (current.isNull())
          return input;
      }
    } while (!(current = current.getNextConsCell()).isNull());
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      naturalMath.put(new ConsCell("negative", ConsType.IDENTIFIER), new ConsCell('-', ConsType.OPERATOR));
      naturalMath.put(new ConsCell("times", ConsType.IDENTIFIER), new ConsCell('*', ConsType.OPERATOR));
      naturalMath.put(new ConsCell("divided", ConsType.IDENTIFIER, new ConsCell("by", ConsType.IDENTIFIER)), new ConsCell('/', ConsType.OPERATOR));
      naturalMath.put(new ConsCell("over", ConsType.IDENTIFIER), new ConsCell('/', ConsType.OPERATOR));
      naturalMath.put(new ConsCell("%", ConsType.OPERATOR, new ConsCell("of", ConsType.IDENTIFIER)), new ConsCell('/', ConsType.OPERATOR,
          new ConsCell(new BigDec(100), ConsType.NUMBER, new ConsCell('*', ConsType.OPERATOR))));
      naturalMath.put(new ConsCell("to", ConsType.IDENTIFIER, new ConsCell("the", ConsType.IDENTIFIER)), new ConsCell('^', ConsType.OPERATOR));
      naturalMath.put(new ConsCell("squared", ConsType.IDENTIFIER), new ConsCell('^', ConsType.OPERATOR, new ConsCell(new BigDec(2), ConsType.NUMBER)));
      naturalMath.put(new ConsCell("cubed", ConsType.IDENTIFIER), new ConsCell('^', ConsType.OPERATOR, new ConsCell(new BigDec(3), ConsType.NUMBER)));
      Object[] nNumbers = {"zero", 0, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9,
          "ten", 10, "eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14, "fifteen", 15, "sixteen", 16, "seventeen", 17, "eightteen", 18, "nineteen", 19,
          "twenty", 20, "thirty", 30, "forty", 40, "fifty", 50, "sixty", 60, "seventy", 70, "eighty", 80, "ninety", 90};
      String[] kys = {"thousand", "million", "billion", "trillion", "quadrillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion",
          "duodecillion", "tredecillion", "quattuordecillion", "quindecillion", "sedecillion", "septendecillion", "octodecillion", "novemdecillion", "viginillion", "centillion"};
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

public final class StatisticsPlugin extends ParserPlugin implements OperationPlugin {
 
  @Override
  public ConsCell runOperation(String operation, ConsCell input) throws ParserException {
    BigDec extra = null;
    if (operation.equals("zScore")) {
      ArrayList<ConsCell> parts = input.splitOnIdentifier(";");
      if (parts.size() != 2)
        throw new ParserException("The input for the zScore function did not include a valid comparator.", this);
      input = parts.get(0);
      extra = new BigDec(parser.run(parts.get(1)).toString());
    }
    ArrayList<ConsCell> list = input.splitOnSeparator();
    BigDec[] items = new BigDec[list.size()];
    for (int i = 0; i < items.length; i++)
      items[i] = new BigDec(parser.run(list.get(i)).toString());
    NumberSet set = new NumberSet(items);
    try {
      if (operation.equals("mean"))
        return new ConsCell(set.getMean(), ConsType.NUMBER);
      if (operation.equals("median"))
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.