Signal on formula evaluation
This commit is contained in:
parent
25ef37f62b
commit
69a08e2872
3 changed files with 14 additions and 3 deletions
4
TODO.md
4
TODO.md
|
|
@ -30,4 +30,6 @@
|
||||||
- [X] From now on, the corpus will be loaded from database instead of assets
|
- [X] From now on, the corpus will be loaded from database instead of assets
|
||||||
- [X] Create method List<FormulaElement> Corpus.withDependencies(Formula formula). It will return the formula, the units of the formula, and all the units from the corpus with the same base unit.
|
- [X] Create method List<FormulaElement> Corpus.withDependencies(Formula formula). It will return the formula, the units of the formula, and all the units from the corpus with the same base unit.
|
||||||
- [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies().
|
- [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies().
|
||||||
- [ ] Replace flutter-markdown with flutter-markdown-plus
|
- [X] Replace flutter-markdown with flutter-markdown-plus
|
||||||
|
- [X] Heron's formula: investigate why a=3, b=40, c=5 yields NaN. Root cause: input values don't form a valid triangle (violate triangle inequality: 3+5=8 is not > 40). Added documentation note to the formula description.
|
||||||
|
- [ ] Investigate starup time when there is no previous database and corpus is loaded from assets.
|
||||||
|
|
|
||||||
|
|
@ -1036,7 +1036,9 @@ Where:
|
||||||
- $a, b, c$: Side lengths (meters)
|
- $a, b, c$: Side lengths (meters)
|
||||||
- $s$: Semi-perimeter $= \frac{a+b+c}{2}$
|
- $s$: Semi-perimeter $= \frac{a+b+c}{2}$
|
||||||
|
|
||||||
This formula is useful when height is unknown.''',
|
This formula is useful when height is unknown.
|
||||||
|
|
||||||
|
**Note:** The side lengths must satisfy the triangle inequality: the sum of any two sides must be greater than the third side (a+b>c, a+c>b, b+c>a). If this condition is not met, the formula returns NaN.''',
|
||||||
"input": [
|
"input": [
|
||||||
{"name": "a", "unit": "meter"}, // Side 1
|
{"name": "a", "unit": "meter"}, // Side 1
|
||||||
{"name": "b", "unit": "meter"}, // Side 2
|
{"name": "b", "unit": "meter"}, // Side 2
|
||||||
|
|
@ -1044,6 +1046,9 @@ This formula is useful when height is unknown.''',
|
||||||
],
|
],
|
||||||
"output": {"name": "A", "unit": "square meter"}, // Area
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||||||
"d4rtCode": """
|
"d4rtCode": """
|
||||||
|
if( a + b < c || a+c < b || b+c < a ){
|
||||||
|
signal( "There is not a valid triangle with those longitudes" );
|
||||||
|
}
|
||||||
var s = (a + b + c) / 2;
|
var s = (a + b + c) / 2;
|
||||||
A = sqrt(s * (s - a) * (s - b) * (s - c));
|
A = sqrt(s * (s - a) * (s - b) * (s - c));
|
||||||
""",
|
""",
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ class FormulaEvaluator {
|
||||||
import "package:d4rt_formulas.dart";
|
import "package:d4rt_formulas.dart";
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
static final String signal = """
|
||||||
|
void signal( String msg ) => throw Exception(msg);
|
||||||
|
""";
|
||||||
|
|
||||||
static const reservedVariableNames = { "variableValues", "indexOf", "variableAllowedValues"} ;
|
static const reservedVariableNames = { "variableValues", "indexOf", "variableAllowedValues"} ;
|
||||||
|
|
||||||
String _buildCompleteSource(Formula formula, Map<String, dynamic> inputValues) {
|
String _buildCompleteSource(Formula formula, Map<String, dynamic> inputValues) {
|
||||||
|
|
@ -169,7 +173,7 @@ class FormulaEvaluator {
|
||||||
|
|
||||||
buffer.writeln("""
|
buffer.writeln("""
|
||||||
$d4rtImports
|
$d4rtImports
|
||||||
|
$signal
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue