package org.simantics.spreadsheet.graph.formula; import org.simantics.spreadsheet.graph.CellFormulaFunction; import org.simantics.spreadsheet.graph.CellValueVisitor; import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; import org.simantics.spreadsheet.graph.parser.ast.AstArgList; public class SqrtFormulaFunction implements CellFormulaFunction { @Override public Object evaluate(CellValueVisitor visitor, AstArgList args) { if (args.values.size() != 1) throw new IllegalStateException(); Object number = args.values.get(0).accept(visitor); Double dVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(number); if(dVal==null) return FormulaError2.handleErrorCall(number); if(dVal<0) return FormulaError2.NUM.getString(); return Math.sqrt(dVal); } }