1 package org.simantics.spreadsheet.graph.formula;
3 import org.simantics.spreadsheet.graph.CellFormulaFunction;
4 import org.simantics.spreadsheet.graph.CellValueVisitor;
5 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
6 import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
8 public class SqrtFormulaFunction implements CellFormulaFunction<Object> {
11 public Object evaluate(CellValueVisitor visitor, AstArgList args) {
12 if (args.values.size() != 1) throw new IllegalStateException();
14 Object number = args.values.get(0).accept(visitor);
15 Double dVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(number);
16 if(dVal==null) return FormulaError2.handleErrorCall(number);
17 if(dVal<0) return FormulaError2.NUM.getString();
19 return Math.sqrt(dVal);