first commit
This commit is contained in:
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
@@ -0,0 +1,21 @@
|
||||
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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user