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

import com.google.common.primitives.Ints;
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 FloatFunction extends TypeConversionFunction
{
  public FloatFunction()
  {
    super("float", "Float", Cres.get().getString("fDescFloat"));
  }
  
  @Override
  public Object convert(Evaluator evaluator, Object parameter) throws EvaluationException
  {
    if (parameter instanceof Data)
    {
      Data data = (Data) parameter;
      parameter = Float.intBitsToFloat(Ints.fromByteArray(data.getData()));
    }
    Number n = Util.convertToNumber(parameter, true, false);
    return n.floatValue();
  }
}
