@Override @SuppressWarnings("unchecked") public <U extends IValue, V extends IValue> Result<U> subscript(Result<?>[] subscripts) { if (subscripts.length > 1) { throw new UnsupportedSubscriptArityError(getType(), subscripts.length, ctx.getCurrentAST()); } Result<IValue> subsBase = (Result<IValue>) subscripts[0]; if (subsBase == null) /* * Wild card not allowed as tuple subscript */ throw new UnsupportedSubscriptError(type, null, ctx.getCurrentAST()); if (!subsBase.getType().isIntegerType()) { throw new UnsupportedSubscriptError( getTypeFactory().integerType(), subsBase.getType(), ctx.getCurrentAST()); } IInteger index = (IInteger) subsBase.getValue(); if (index.intValue() >= getValue().arity()) { throw RuntimeExceptionFactory.indexOutOfBounds( index, ctx.getCurrentAST(), ctx.getStackTrace()); } Type elementType = getType().getFieldType(index.intValue()); IValue element = getValue().get(index.intValue()); return makeResult(elementType, element, ctx); }
public void arbSeed(IInteger seed) { random.setSeed(seed.intValue()); }
public IValue arbInt(IInteger limit) // @doc{arbInt -- return an arbitrary integer value in the interval [0, limit).} { // TODO allow big ints return values.integer(random.nextInt(limit.intValue())); }
public IValue toReal(IInteger n) // @doc{toReal -- convert a rational value to a integer value.} { return values.real(n.intValue()); }
public IValue setPrecision(IInteger precision) { return values.integer(values.setPrecision(precision.intValue())); }
public IValue precision(INumber x, IInteger precision) { return values.real(x.toString(), precision.intValue()); }