Package wyautl.util

Examples of wyautl.util.BigRational


    Automaton.Bag terms = (Automaton.Bag) automaton.get(args.get(1));

    // Must use abs() here, otherwise can end up with negative gcd.
    // This is problematic for inequalities as it necessitate
    // changing their sign.
    BigRational gcd = constant.value.abs();

    if(gcd.equals(BigRational.ZERO)) {
      // Basically, if there is no coefficient, then ignore it.
      gcd = null;
    }

    // Now, iterate through each term examining its coefficient and
    // determining the GreatestCommonDivisor of the whole lot.
    for(int i=0;i!=terms.size();++i) {
      int child = terms.get(i);
      Automaton.Term mul = (Automaton.Term) automaton.get(child);
      Automaton.List ls = (Automaton.List) automaton.get(mul.contents);
      Automaton.Real coefficient = (Automaton.Real) automaton.get(ls.get(0));
      BigRational val = coefficient.value;
      if(gcd == null) {
        // Must use abs() here, otherwise can end up with negative gcd.
        // This is problematic for inequalities as it necessitate
        // changing their sign.
        gcd = val.abs();
      } else {
        // Note, gcd of two numbers (either of which may be negative) is
        // always positive.
        gcd = gcd.gcd(val);
      }
View Full Code Here


          index - 1));
    } else if (token instanceof Int) {
      BigInteger val = match(Int.class).value;
      return new Expr.Constant(val, sourceAttr(start, index - 1));
    } else if (token instanceof Real) {
      BigRational val = match(Real.class).value;
      return new Expr.Constant(val, sourceAttr(start,
          index - 1));
    } else if (token instanceof Strung) {
      return parseString();
    } else if (token instanceof Minus) {
View Full Code Here

    } else if (value instanceof Value.Integer) {
      Value.Integer v = (Value.Integer) value;
      return Num(automaton , BigRational.valueOf(v.value));
    } else if (value instanceof Value.Decimal) {
      Value.Decimal v = (Value.Decimal) value;
      return Num(automaton, new BigRational(v.value));
    } else if (value instanceof Value.String) {
      Value.String v = (Value.String) value;
      return Solver.String(automaton,v.value);
    } else if (value instanceof Value.Set) {
      Value.Set vs = (Value.Set) value;
View Full Code Here

        return new Int(r,input.substring(start,pos),start);
      }
      while (pos < input.length() && Character.isDigit(input.charAt(pos))) {
        pos = pos + 1;
      }
      BigRational r = new BigRational(input.substring(start, pos));
      return new Real(r,input.substring(start,pos),start);
    } else {
      BigInteger r = new BigInteger(input.substring(start, pos));
      return new Int(r,input.substring(start,pos),start);
    }
View Full Code Here

    public Real(long value) {
      super(K_REAL, BigRational.valueOf(value));
    }

    public Real(String str) {
      super(K_REAL, new BigRational(str));
    }
View Full Code Here

      } else {
        rhs = "new Automaton.Int(\"" + bi.toString() + "\")";
      }

    } else if (v instanceof BigRational) {
      BigRational br = (BigRational) v;
      rhs = "new Automaton.Real(\"" + br.toString() + "\")";
      if (br.isInteger()) {
        long lv = br.longValue();
        if (BigRational.valueOf(lv).equals(br)) {
          // Yes, this will fit in a long value. Therefore, inline a
          // long constant as this is faster.
          rhs = "new Automaton.Real(" + lv + ")";
        }
View Full Code Here

  }

  protected void translate(Constant.Decimal e, int freeSlot,
      ArrayList<Bytecode> bytecodes) {
    BigRational rat = new BigRational(e.value);
    BigInteger den = rat.denominator();
    BigInteger num = rat.numerator();
    if(rat.isInteger()) {
      // this
      if(num.bitLength() < 32) {
        bytecodes.add(new Bytecode.LoadConst(num.intValue()));
        JvmType.Function ftype = new JvmType.Function(WHILEYRAT,T_INT);
        bytecodes.add(new Bytecode.Invoke(WHILEYRAT, "valueOf", ftype,
View Full Code Here

    byte[] numerator = new byte[size];
    reader.read(numerator);
    size = reader.read_uv();
    byte[] denominator = new byte[size];
    reader.read(denominator);
    return new Automaton.Real(new BigRational(new BigInteger(numerator),
        new BigInteger(denominator)));
  }
View Full Code Here

      Automaton.Int i = (Automaton.Int) state;
      byte[] bytes = i.value.toByteArray();
      output.write_uv(bytes.length);
    } else if (state instanceof Automaton.Real) {
      Automaton.Real r = (Automaton.Real) state;
      BigRational br = r.value;

      byte[] numbytes = br.numerator().toByteArray();
      output.write_uv(numbytes.length);
      output.write(numbytes);

      byte[] denbytes = br.denominator().toByteArray();
      output.write_uv(denbytes.length);

    } else if (state instanceof Automaton.Strung) {
      Automaton.Strung str = (Automaton.Strung) state;
      try {
View Full Code Here

      sb.append((char) next());
      while ((lookahead = lookahead()) != -1
          && Character.isDigit((char) lookahead)) {
        sb.append((char) next());
      }
      BigRational val = new BigRational(sb.toString());

      if(negative) {
        val = val.negate();
      }

      return automaton.add(new Automaton.Real(val));

    } else {
      BigInteger val = new BigInteger(sb.toString());

      if(negative) {
        val = val.negate();
      }

      return automaton.add(new Automaton.Int(val));
    }
  }
View Full Code Here

TOP

Related Classes of wyautl.util.BigRational

Copyright © 2018 www.massapicom. 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.