当前位置: 首页>>代码示例>>Java>>正文


Java NumericType类代码示例

本文整理汇总了Java中gov.nasa.jpf.constraints.types.NumericType的典型用法代码示例。如果您正苦于以下问题:Java NumericType类的具体用法?Java NumericType怎么用?Java NumericType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NumericType类属于gov.nasa.jpf.constraints.types包,在下文中一共展示了NumericType类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeIntegerCast

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private <F,T,TT extends Type<T>>
Expr makeIntegerCast(IntExpr castedExpr, IntegerType<F> from, TT to) throws Z3Exception {
  try {
    if(to instanceof BVIntegerType) {
      BVIntegerType<?> bvTo = (BVIntegerType<?>)to;
      return ctx.mkInt2BV(bvTo.getNumBits(), castedExpr);
    }
    if(to instanceof IntegerType) {
      Expr tmp = castedExpr;
      castedExpr = null; // prevent disposal
      return tmp;
    }
    if(to instanceof NumericType) {
      return ctx.mkInt2Real(castedExpr);
    }
    throw new IllegalStateException("Cannot handle integer cast to " + to);
  }
  finally {
    safeDispose(castedExpr);
  }
}
 
开发者ID:psycopaths,项目名称:jconstraints-z3,代码行数:22,代码来源:NativeZ3ExpressionGenerator.java

示例2: visit

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public <E> Expr visit(
    NumericCompound<E> n, Void data) {
  Expr left = null, right = null;
  
  try {
    left = visit(n.getLeft());
    right = visit(n.getRight());
    
    NumericType<E> type = (NumericType<E>)n.getType();
    
    if(type instanceof BVIntegerType)
      return makeBitvectorNumericCompound(n.getOperator(), type.isSigned(), (BitVecExpr)left, (BitVecExpr)right);
    
    return makeArithmeticNumericCompound(n.getOperator(), (ArithExpr)left, (ArithExpr)right);
  }
  catch(Z3Exception ex) {
    throw new RuntimeException(ex);
  }
  finally {
    safeDispose(left, right);
  }
}
 
开发者ID:psycopaths,项目名称:jconstraints-z3,代码行数:24,代码来源:NativeZ3ExpressionGenerator.java

示例3: evaluate

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public E evaluate(Valuation values) {
  E lv = left.evaluate(values);
  E rv = right.evaluate(values);

  NumericType<E> type = (NumericType<E>)getType();
  switch (operator) {
  case PLUS:
    return type.plus(lv, rv);
  case MINUS:
    return type.minus(lv, rv);
  case MUL:
    return type.mul(lv, rv);
  case DIV:
    return type.div(lv, rv);
  case REM:
    return type.mod(lv, rv);
  default:
    throw new IllegalStateException("Unknown numeric operator " + operator);
  }
}
 
开发者ID:psycopaths,项目名称:jconstraints,代码行数:22,代码来源:NumericCompound.java

示例4: visit

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public <E> Expression<?> visit(Constant<E> c, Boolean data) {
  if(!data)
    return c;
  
  Expression<Boolean> asBool = c.as(BuiltinTypes.BOOL);
  
  if(asBool != null)
    return ExpressionUtil.boolConst(!asBool.evaluate(null));
  
  Type<E> t = c.getType();
  if(t instanceof NumericType) {
    NumericType<E> nt = (NumericType<E>)t;
    return Constant.create(nt, nt.negate(c.getValue()));
  }
  throw new IllegalStateException("Cannot simplify: expression of type " + c.getType() + " is neither boolean nor numeric");
}
 
开发者ID:psycopaths,项目名称:jconstraints,代码行数:18,代码来源:ExpressionSimplificationVisitor.java

示例5: doEvaluate

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private static <L,R> int doEvaluate(Expression<L> left, Expression<R> right, Valuation values) {
  NumericType<L> lt = (NumericType<L>)left.getType();
  NumericType<R> rt = (NumericType<R>)right.getType();
  
  L lv = left.evaluate(values);
  R rv = right.evaluate(values);
  
  BigDecimal lnum = lt.decimalValue(lv), rnum = rt.decimalValue(rv);
  
  return lnum.compareTo(rnum);
}
 
开发者ID:psycopaths,项目名称:jdart,代码行数:12,代码来源:NumericCMP.java

示例6: makeRealCast

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private <F,T,TT extends Type<T>>
Expr makeRealCast(RealExpr castedExpr, NumericType<F> from, TT to) throws Z3Exception {
  try {
    if(to instanceof BVIntegerType) {
      BVIntegerType<?> bvTo = (BVIntegerType<?>)to;
      IntExpr intTmp = null;
      try {
        intTmp = makeReal2IntTrunc(castedExpr);
        return ctx.mkInt2BV(bvTo.getNumBits(), intTmp);
      }
      finally {
        uncheckedDispose(intTmp);
      }
    }
    if(to instanceof IntegerType) {
      return makeReal2IntTrunc(castedExpr);
    }
    if(to instanceof NumericType) {
      Expr tmp = castedExpr;
      castedExpr = null; // prevent disposal
      return tmp;
    }
    throw new IllegalStateException("Cannot handle integer cast to " + to);
  }
  finally {
    safeDispose(castedExpr);
  }
}
 
开发者ID:psycopaths,项目名称:jconstraints-z3,代码行数:29,代码来源:NativeZ3ExpressionGenerator.java

示例7: translateTypeCast

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
public Expression<?> translateTypeCast(Tree n) {
  requireType(n, TYPE_CAST);
  
  NumericType<?> toType = (NumericType<?>)translateType(n.getChild(0));
  Expression<?> fromExpr = translateArithmeticExpression(n);
  
  return CastExpression.create(fromExpr, toType);
}
 
开发者ID:psycopaths,项目名称:jconstraints,代码行数:9,代码来源:ASTTranslator.java

示例8: compare

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private static <L,R> int compare(Expression<L> left, Expression<R> right, Valuation val) {
  L lv = left.evaluate(val);
  R rv = right.evaluate(val);
  NumericType<L> ltype = (NumericType<L>)left.getType();
  NumericType<R> rtype = (NumericType<R>)right.getType();
  
  if (ltype.equals(rtype)) {
      return ltype.compare(lv, (L) rv);
  }
  
  BigDecimal lNum = ltype.decimalValue(lv);
  BigDecimal rNum = rtype.decimalValue(rv);
  return lNum.compareTo(rNum);
}
 
开发者ID:psycopaths,项目名称:jconstraints,代码行数:15,代码来源:NumericBooleanExpression.java

示例9: evaluate

import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public E evaluate(Valuation values) {
  E num = negated.evaluate(values);
  NumericType<E> type = (NumericType<E>)getType();
  return type.negate(num);
}
 
开发者ID:psycopaths,项目名称:jconstraints,代码行数:7,代码来源:UnaryMinus.java


注:本文中的gov.nasa.jpf.constraints.types.NumericType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。