sync with reality?

This commit is contained in:
rusefi 2020-09-10 21:36:37 -04:00
parent 370c107793
commit de572db0bc
3 changed files with 15 additions and 2 deletions

View File

@ -53,4 +53,4 @@ STARTER_RELAY_LOGIC=rpm < cranking_rpm
BOOST_CONTROLLER=fsio_table (3, rpm, map) / 100 BOOST_CONTROLLER=fsio_table (3, rpm, map) / 100
ANALOG_CONDITION=if(fsio_input (0) > 20, 0, 10) ANALOG_CONDITION=if(fsio_analog_input (0) > 20, 0, 10)

View File

@ -1,6 +1,8 @@
package com.fathzer.soft.javaluator; package com.fathzer.soft.javaluator;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/** An abstract evaluator, able to evaluate infix expressions. /** An abstract evaluator, able to evaluate infix expressions.
* <br>Some standard evaluators are included in the library, you can define your own by subclassing this class. * <br>Some standard evaluators are included in the library, you can define your own by subclassing this class.
@ -184,7 +186,13 @@ public abstract class AbstractEvaluator<T> {
System.out.println("doFunction " + function + " " + argCount); System.out.println("doFunction " + function + " " + argCount);
if (function.getMinimumArgumentCount()>argCount || function.getMaximumArgumentCount()<argCount) { if (function.getMinimumArgumentCount()>argCount || function.getMaximumArgumentCount()<argCount) {
throw new IllegalArgumentException("Invalid argument count for "+function.getName() + " while " + argCount); Iterator<?> a = getArguments(values, argCount);
Iterable iterable = () -> a;
List actualList = (List) StreamSupport
.stream(iterable.spliterator(), false)
.collect(Collectors.toList());
throw new IllegalArgumentException("Invalid argument count for "+function.getName() + " while " + argCount + ": " + actualList);
} }
values.push(evaluate(function, getArguments(values, argCount), evaluationContext)); values.push(evaluate(function, getArguments(values, argCount), evaluationContext));
} }

View File

@ -245,6 +245,11 @@ public class DoubleEvaluator extends AbstractEvaluator<Double> {
ParsePosition p = new ParsePosition(0); ParsePosition p = new ParsePosition(0);
Number result = FORMATTER.get().parse(literal, p); Number result = FORMATTER.get().parse(literal, p);
if (p.getIndex() == 0 || p.getIndex() != literal.length()) { if (p.getIndex() == 0 || p.getIndex() != literal.length()) {
/**
* We are here if function is not know
* TODO: shall we throw exception?
*/
System.err.println("Not known " + literal);
return 6666666.0; // let's return this magic in case of any function call return 6666666.0; // let's return this magic in case of any function call
// throw new IllegalArgumentException(literal + " is not a number"); // throw new IllegalArgumentException(literal + " is not a number");
} }