private Value evalToCharSequenceInternal(final Function<String, Value> variables, final int rangeIdx) {
            final ValueList childValues = new ValueList();
            boolean hasError = false;
            for (FormulaNode child : children) {
                final Value v = child.evalToCharSequenceInternal(variables, rangeIdx);
                if (v instanceof ErrorValue) {
                    hasError = true;
                }
                childValues.add(v);
            }
            Set<Integer> childsInError = null;
            if (!hasError) {
                try {
                    return this.function.call(childValues, variables, rangeIdx);
                } catch (FormulaException fe) {
                    //error is right here...
                    childsInError = fe.getChildrenInError();
                }
            }

            //we had an error in the chain -> produce a String using the error function
            CharSequence cs = null;
            if (this.functionToErrorString != null) {
                cs = this.functionToErrorString.call(childValues, variables, rangeIdx, childsInError);
            }
            if (cs == null) {
                cs = optionalError(valueListToCharSequence(childValues), childsInError);
            }
            return ErrorValue.of(cs);
        }
This class represents a Formula which is parsed from a String variable.
<br>
The originally rather simple evaluation algorithm was derived from the work of user 'Boann' and released to the public domain on Stack Overflow
<a href="https://stackoverflow.com/questions/3422673/evaluating-a-math-expression-given-in-string-form">here</a>
<br>
Since then, various additions made the evaluation algorithm a bit more complex. The following features were added:
<br>
* Operators '%' and also '!'.
* Ability to evaluate functions, e.g.  'sqrt', 'cos', 'sin' and 'tan' .
* Support for variables (insertion of values)
* Class now also supports precompilation of expressions and reuse of this compile generate for other variable values
* LRUCache added to store and reuse previously compiled expressions
* Ability to use string type was added (in addition to numeric)
* concated expressions were added. For example '3(5+1)4' is now interpreted as '364'. Likewise, if A=1, then 'AA5(A+1)3' will  be parsed to '11523'
* Localizable, user-displayable error message handling was added.
main/src/main/java/cgeo/geocaching/utils/formulas/Formula.java