A MathFunction for Math#log(double) log2(x) log3(x) ... log[BASE](x)
| 14 | * log[BASE](x) |
| 15 | */ |
| 16 | public class LogFunction implements MathFunction { |
| 17 | int base; |
| 18 | |
| 19 | @Override |
| 20 | public String name() { |
| 21 | return "log"; |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public boolean compareNames(String name) { |
| 26 | if (name.trim().toLowerCase().startsWith("log")) { |
| 27 | name = name.substring(3); |
| 28 | if (Utils.isUnsignedInteger(name)) { |
| 29 | base = Integer.parseInt(name); |
| 30 | return true; |
| 31 | } |
| 32 | } |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public double calculate(Object... parameters) { |
| 38 | return Functions.log((double) parameters[0], base); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public int getParameterCount() { |
| 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean isSpecialParameter(int index) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void attachToParser(MathParser parser) { |
| 53 | } |
| 54 | } |
nothing calls this directly
no outgoing calls
no test coverage detected