use of gov.sandia.n2a.language.operator.Negate in project n2a by frothga.
the class Scalar method convert.
/**
* General utility: given a string containing a number with units, convert to the scaled SI value.
*/
public static double convert(String expression) {
try {
Operator op = Operator.parse(expression);
double sign = 1;
if (op instanceof Negate) {
op = ((Negate) op).operand;
sign = -1;
}
if (!(op instanceof Constant))
return 0;
Type result = ((Constant) op).value;
if (result instanceof Scalar)
return ((Scalar) result).value * sign;
} catch (ParseException e) {
}
return 0;
}
Aggregations