package org.nfunk.jep.function;

import java.util.Stack;
import org.nfunk.jep.ParseException;
import org.nfunk.jep.type.Complex;

public class Arg extends PostfixMathCommand {
  private static final Double ONE = new Double(1.0D);
  
  public void run(Stack paramStack) throws ParseException {
    checkStack(paramStack);
    Object object = paramStack.pop();
    paramStack.push(arg(object));
  }
  
  public Number arg(Object paramObject) throws ParseException {
    if (paramObject instanceof Complex)
      return new Double(((Complex)paramObject).arg()); 
    if (paramObject instanceof Number)
      return ONE; 
    throw new ParseException("Invalid parameter type");
  }
}
