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