]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SqrtFormulaFunction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / formula / SqrtFormulaFunction.java
1 package org.simantics.spreadsheet.graph.formula;
2
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;
7
8 public class SqrtFormulaFunction implements CellFormulaFunction<Object> {
9
10     @Override
11     public Object evaluate(CellValueVisitor visitor, AstArgList args) {
12         if (args.values.size() != 1) throw new IllegalStateException();
13         
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();
18
19         return Math.sqrt(dVal);
20     }
21 }