2010-02-23 01:33:39 +01:00
|
|
|
package com.metaweb.gridworks.expr.functions;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2010-02-23 02:40:06 +01:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
2010-02-27 06:48:33 +01:00
|
|
|
import com.metaweb.gridworks.expr.ControlFunctionRegistry;
|
2010-02-23 01:33:39 +01:00
|
|
|
import com.metaweb.gridworks.expr.Function;
|
2010-02-27 06:48:33 +01:00
|
|
|
import com.metaweb.gridworks.expr.EvalError;
|
2010-02-23 01:33:39 +01:00
|
|
|
|
|
|
|
public class Log implements Function {
|
|
|
|
|
|
|
|
public Object call(Properties bindings, Object[] args) {
|
2010-02-27 06:48:33 +01:00
|
|
|
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
2010-02-23 01:33:39 +01:00
|
|
|
return Math.log10(((Number) args[0]).doubleValue());
|
|
|
|
}
|
2010-02-27 06:48:33 +01:00
|
|
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
2010-02-23 01:33:39 +01:00
|
|
|
}
|
|
|
|
|
2010-02-23 02:40:06 +01:00
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("description"); writer.value("Returns the base 10 log of n");
|
|
|
|
writer.key("params"); writer.value("number n");
|
|
|
|
writer.key("returns"); writer.value("number");
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-02-23 01:33:39 +01:00
|
|
|
}
|