use of org.apache.asterix.om.base.AMutableDouble in project asterixdb by apache.
the class Operation method compareReals.
public static void compareReals(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
AMutableDouble r1 = objectPool.doublePool.get();
AMutableDouble r2 = objectPool.doublePool.get();
boolean compResult = false;
v1.isRealValue(r1);
v2.isRealValue(r2);
switch(op) {
case OpKind_LESS_THAN_OP:
compResult = (r1.getDoubleValue() < r2.getDoubleValue());
break;
case OpKind_LESS_OR_EQUAL_OP:
compResult = (r1.getDoubleValue() <= r2.getDoubleValue());
break;
case OpKind_EQUAL_OP:
compResult = (r1.getDoubleValue() == r2.getDoubleValue());
break;
case OpKind_META_EQUAL_OP:
compResult = (r1.getDoubleValue() == r2.getDoubleValue());
break;
case OpKind_NOT_EQUAL_OP:
compResult = (r1.getDoubleValue() != r2.getDoubleValue());
break;
case OpKind_META_NOT_EQUAL_OP:
compResult = (r1.getDoubleValue() != r2.getDoubleValue());
break;
case OpKind_GREATER_THAN_OP:
compResult = (r1.getDoubleValue() > r2.getDoubleValue());
break;
case OpKind_GREATER_OR_EQUAL_OP:
compResult = (r1.getDoubleValue() >= r2.getDoubleValue());
break;
default:
// should not get here
throw new HyracksDataException("Should not get here");
}
result.setBooleanValue(compResult);
}
use of org.apache.asterix.om.base.AMutableDouble in project asterixdb by apache.
the class Operation method doRealArithmetic.
public static int doRealArithmetic(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
AMutableDouble r1 = objectPool.doublePool.get();
AMutableDouble r2 = objectPool.doublePool.get();
double comp = 0;
// we want to prevent FPE and set the ERROR value on the result; on Unix
// trap sigfpe and set the ClassAdExprFPE flag to true; on NT check the
// result against HUGE_VAL. check errno for EDOM and ERANGE for kicks.
v1.isRealValue(r1);
v2.isRealValue(r2);
int errno = 0;
switch(op) {
case OpKind_ADDITION_OP:
comp = r1.getDoubleValue() + r2.getDoubleValue();
break;
case OpKind_SUBTRACTION_OP:
comp = r1.getDoubleValue() - r2.getDoubleValue();
break;
case OpKind_MULTIPLICATION_OP:
comp = r1.getDoubleValue() * r2.getDoubleValue();
break;
case OpKind_DIVISION_OP:
comp = r1.getDoubleValue() / r2.getDoubleValue();
break;
case OpKind_MODULUS_OP:
errno = EDOM;
break;
default:
// should not reach here
throw new HyracksDataException("Should not get here");
}
// check if anything bad happened
if (errno == EDOM) {
result.setErrorValue();
} else {
result.setRealValue(comp);
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
use of org.apache.asterix.om.base.AMutableDouble in project asterixdb by apache.
the class Value method convertValueToIntegerValue.
public static boolean convertValueToIntegerValue(Value value, Value integerValue, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean could_convert;
AMutableCharArrayString buf = objectPool.strPool.get();
char end;
AMutableInt64 ivalue = objectPool.int64Pool.get();
AMutableDouble rtvalue = objectPool.doublePool.get();
ClassAdTime atvalue = objectPool.classAdTimePool.get();
MutableBoolean bvalue = objectPool.boolPool.get();
NumberFactor nf;
switch(value.getType()) {
case UNDEFINED_VALUE:
integerValue.setUndefinedValue();
could_convert = false;
break;
case ERROR_VALUE:
case CLASSAD_VALUE:
case LIST_VALUE:
case SLIST_VALUE:
integerValue.setErrorValue();
could_convert = false;
break;
case STRING_VALUE:
could_convert = true;
value.isStringValue(buf);
int endIndex = buf.firstNonDigitChar();
if (endIndex < 0) {
// no non digit
ivalue.setValue(Long.parseLong(buf.toString()));
nf = NumberFactor.NO_FACTOR;
break;
} else {
ivalue.setValue(Long.parseLong(buf.substr(0, endIndex)));
end = buf.charAt(endIndex);
switch(Character.toUpperCase(end)) {
case 'B':
nf = NumberFactor.B_FACTOR;
break;
case 'K':
nf = NumberFactor.K_FACTOR;
break;
case 'M':
nf = NumberFactor.M_FACTOR;
break;
case 'G':
nf = NumberFactor.G_FACTOR;
break;
case 'T':
nf = NumberFactor.T_FACTOR;
break;
case '\0':
nf = NumberFactor.NO_FACTOR;
break;
default:
nf = NumberFactor.NO_FACTOR;
break;
}
if (could_convert) {
integerValue.setIntegerValue((long) ((ivalue.getLongValue() * Value.ScaleFactor[nf.ordinal()])));
}
}
break;
case BOOLEAN_VALUE:
value.isBooleanValue(bvalue);
integerValue.setIntegerValue(bvalue.booleanValue() ? 1 : 0);
could_convert = true;
break;
case INTEGER_VALUE:
integerValue.setValue(value);
could_convert = true;
break;
case REAL_VALUE:
value.isRealValue(rtvalue);
integerValue.setIntegerValue((long) rtvalue.getDoubleValue());
could_convert = true;
break;
case ABSOLUTE_TIME_VALUE:
value.isAbsoluteTimeValue(atvalue);
integerValue.setIntegerValue(atvalue.getTimeInMillis() / 1000L);
could_convert = true;
break;
case RELATIVE_TIME_VALUE:
value.isRelativeTimeValue(atvalue);
integerValue.setIntegerValue((atvalue.getTime() / 1000L));
could_convert = true;
break;
default:
// Make gcc's -Wuninitalized happy
could_convert = false;
throw new HyracksDataException("Should not reach here");
}
return could_convert;
}
use of org.apache.asterix.om.base.AMutableDouble in project asterixdb by apache.
the class Literal method privateEvaluate.
@Override
public boolean privateEvaluate(EvalState eval, Value val) throws HyracksDataException {
AMutableInt64 i = objectPool.int64Pool.get();
AMutableDouble r = objectPool.doublePool.get();
val.setValue(value);
// if integer or real, multiply by the factor
if (val.isIntegerValue(i)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
} else {
val.setIntegerValue(i.getLongValue());
}
} else if (val.isRealValue(r)) {
val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
}
return true;
}
use of org.apache.asterix.om.base.AMutableDouble in project asterixdb by apache.
the class Literal method GetValue.
public void GetValue(Value val) throws HyracksDataException {
AMutableInt64 i = objectPool.int64Pool.get();
AMutableDouble r = objectPool.doublePool.get();
val.setValue(value);
// if integer or real, multiply by the factor
if (val.isIntegerValue(i)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
}
} else if (val.isRealValue(r)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
}
}
}
Aggregations