use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Input method determineExponentNext.
public void determineExponentNext() {
String mode = getMode();
boolean time = mode.contains("time") || mode.contains("smooth");
if (operands.length > 1) {
Operator op = operands[1];
if (time)
op.exponentNext = exponentTime;
else
// We expect an integer.
op.exponentNext = MSB;
op.determineExponentNext();
}
if (operands.length > 2) {
Operator op = operands[2];
// We expect an integer.
op.exponentNext = MSB;
op.determineExponentNext();
}
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Norm method determineExponent.
public void determineExponent(ExponentContext context) {
// A
Operator op0 = operands[0];
op0.determineExponent(context);
// n
Operator op1 = null;
if (operands.length > 1) {
op1 = operands[1];
op1.determineExponent(context);
}
Instance instance = new Instance() {
// all AccessVariable objects will reach here first, and get back the Variable.type field
public Type get(VariableReference r) throws EvaluationException {
return r.variable.type;
}
};
Matrix A = (Matrix) op0.eval(instance);
int Asize = A.rows() * A.columns();
int centerNew = center;
int exponentNew = exponent;
if (op0.exponent != UNKNOWN) {
// For n==1 (sum of elements), which is the most expensive in terms of bits.
int shift = (int) Math.floor(Math.log(Asize) / Math.log(2));
// Don't shift center into negative territory.
shift = Math.min(op0.center, shift);
centerNew = op0.center - shift;
exponentNew = op0.exponent + shift;
}
if (op1 instanceof Constant) {
double n = op1.getDouble();
if (n == 0) {
// Result is an integer
centerNew = 0;
exponentNew = MSB;
} else if (Double.isInfinite(n)) {
centerNew = op0.center;
exponentNew = op0.exponent;
}
// It would be nice to have some way to interpolate between the 3 bounding cases.
}
updateExponent(context, exponentNew, centerNew);
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Norm method determineExponentNext.
public void determineExponentNext() {
// A
Operator op0 = operands[0];
op0.exponentNext = op0.exponent;
op0.determineExponentNext();
if (operands.length > 1) {
// n
Operator op1 = operands[1];
op1.exponentNext = Operator.MSB / 2;
op1.determineExponentNext();
}
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Atan method determineExponentNext.
public void determineExponentNext() {
Operator y = operands[0];
int next;
if (operands.length == 1) {
if (y.getType() instanceof Matrix) {
next = y.exponent;
} else {
// atan(y) = atan2(y,1), so treat x as 1
// If y is so small that all its bits are lost, then angle can be treated as zero.
// If y is so large that all the bits of x are lost, then angle can be treated as pi.
next = Math.max(0, y.exponent);
}
} else {
Operator x = operands[1];
next = Math.max(x.exponent, y.exponent);
x.exponentNext = next;
x.determineExponentNext();
}
y.exponentNext = next;
y.determineExponentNext();
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Delay method determineExponentNext.
public void determineExponentNext() {
// Assumes that we simply output the same exponent as our inputs.
exponent = exponentNext;
Operator value = operands[0];
// Passes the required exponent down to operands.
value.exponentNext = exponentNext;
value.determineExponentNext();
if (operands.length > 1) {
Operator delta = operands[1];
// delta.exponentNext already set in determineExponent()
delta.determineExponentNext();
}
if (operands.length > 2) {
Operator defaultValue = operands[2];
defaultValue.exponentNext = exponentNext;
defaultValue.determineExponentNext();
}
}
Aggregations