package com.tibbo.aggregate.common.expression.function.type;

import com.google.common.primitives.Longs;
import com.tibbo.aggregate.common.Cres;
import com.tibbo.aggregate.common.data.Data;
import com.tibbo.aggregate.common.expression.EvaluationException;
import com.tibbo.aggregate.common.expression.Evaluator;
import com.tibbo.aggregate.common.util.Util;

public class DoubleFunction extends TypeConversionFunction
{
  public DoubleFunction()
  {
    super("double","Double", Cres.get().getString("fDescDouble"));
  }
  
  @Override
  public Object convert(Evaluator evaluator, Object parameter) throws EvaluationException
  {
    if (parameter instanceof Data)
    {
      Data data = (Data) parameter;
      parameter = Double.longBitsToDouble(Longs.fromByteArray(data.getData()));
    }
    Number n = Util.convertToNumber(parameter, true, false);
    return n.doubleValue();
  }
}
