first commit
This commit is contained in:
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class SquareRoot extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sqrt(object));
|
||||
}
|
||||
|
||||
public Object sqrt(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sqrt();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return (d < 0.0D) ? (new Complex(d)).sqrt() : new Double(Math.sqrt(d));
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user