2

I have a Dictionary<string, double> values and values precision is important for me. I have a string Formula that Infix can Parse. I wonder how to do something like this:

var expr = Infix.ParseOrThrow(m.Formula);
var result = Evaluate.Evaluate<double>(values, expr);

to get a result with double precision?

TylerH
  • 20,799
  • 66
  • 75
  • 101
DuckQueen
  • 772
  • 10
  • 62
  • 134
  • 1
    @Alex: if these tags have the same meaning, please put effort into merging them, rather than adding redundant tags to questions. https://meta.stackoverflow.com/questions/369717/tags-mathdotnet-and-mathnet-seem-to-be-redundant Thanks! – Cris Luengo Aug 20 '19 at 17:34
  • @CrisLuengo, I'm interested in the tag. So I tried to add synonyms. It is said that synonyms have allready been proposed. But one still have to search for three different tags to find all `mathnet` questions. – CSDev Aug 21 '19 at 08:23
  • @Alex: please read here: https://meta.stackexchange.com/questions/70710/what-are-tag-synonyms-and-merged-tags-how-do-they-work – Cris Luengo Aug 21 '19 at 12:22
  • @CrisLuengo, I got it. Thanks. – CSDev Aug 21 '19 at 13:45

1 Answers1

1

Evaluate operates on a custom FloatingPoint type which can represent various double-precision floating-point values (mostly real or complex numbers, in theory also vectors or matrices). You can cast a double to a FloatingPoint, and use RealValue to get a double back from a FloatingPoint.

Example:

var variables = new Dictionary<string,FloatingPoint>
   {{ "a", 2.0 },
    { "b", 3.0 }};

var expr = Infix.ParseOrThrow("2/3*a");
double result = Evaluate.Evaluate(variables, expr).RealValue;
Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34