public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException
{
final int parameterCount = parameters.getParameterCount();
if (parameterCount != 2)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
}
final TypeRegistry typeRegistry = context.getTypeRegistry();
final Type textType1 = parameters.getType(0);
final Object textValue1 = parameters.getValue(0);
final Type textType2 = parameters.getType(1);
final Object textValue2 = parameters.getValue(1);
// Numerical comparisons ignore "trivial" differences that
// depend only on numeric precision of finite numbers.
// This fixes the common rounding errors, that are encountered when computing "((1/3) * 3)", which results
// in 0.99999 and not 1, as expected.
try
{
final Number number1 = typeRegistry.convertToNumber(textType1, textValue1);
final Number number2 = typeRegistry.convertToNumber(textType2, textValue2);
final double delta = Math.abs(Math.abs(number1.doubleValue()) - Math.abs(number2.doubleValue()));
if(delta < 0.00005)
{
return RETURN_TRUE;
}
return RETURN_FALSE;
}
catch(TypeConversionException tce)
{
// Ignore, try to compare them as strings ..
}
final String text1 = typeRegistry.convertToText(textType1, textValue1);
final String text2 = typeRegistry.convertToText(textType2, textValue2);
if(text1 == null || text2 == null)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
if (text1.equals(text2))
{
return RETURN_TRUE;