22 lines
677 B
Java
22 lines
677 B
Java
package org.nfunk.jep.function;
|
|
|
|
import java.util.Stack;
|
|
import org.nfunk.jep.ParseException;
|
|
import org.nfunk.jep.type.Complex;
|
|
|
|
public class Abs extends PostfixMathCommand {
|
|
public void run(Stack paramStack) throws ParseException {
|
|
checkStack(paramStack);
|
|
Object object = paramStack.pop();
|
|
paramStack.push(abs(object));
|
|
}
|
|
|
|
public Object abs(Object paramObject) throws ParseException {
|
|
if (paramObject instanceof Complex)
|
|
return new Double(((Complex)paramObject).abs());
|
|
if (paramObject instanceof Number)
|
|
return new Double(Math.abs(((Number)paramObject).doubleValue()));
|
|
throw new ParseException("Invalid parameter type");
|
|
}
|
|
}
|