public void CreateDecimalTest() { var d = Dec.Create(0.5m); Assert.AreEqual(d, Literal.Create(1) / Literal.Create(2)); Assert.AreEqual(d.ToString(), "0.5"); }
public void CreateDecimalTest2() { var d = Dec.Create(0.33333333333333m); Assert.AreEqual(d, Literal.Create(1) / Literal.Create(3)); Assert.AreEqual(d.ToString(), "0.33333333333333"); }
public void Beta1Formula() { var actual = ExprParser.ParseOrThrow("0.85-(0.05/7)*(fᐠ_c-28)"); var expected = Dec.Create(0.85m) - (Dec.Create(0.05m) / Literal.Create(7)) * (new Identifier("fᐠ_c") - Literal.Create(28)); Assert.AreEqual(expected, actual); Assert.AreEqual("0.85-((0.05/7)×(fᐠ_c-28))", actual.ToString()); var substiResult = actual.Substitute(new Identifier("fᐠ_c"), 32).Simplify(); Assert.AreEqual(substiResult, DivideOp.Create(23, 28)); if (substiResult.TryToDouble(out var val)) { Assert.AreEqual(0.8214, val, 0.0001); } else { Assert.Fail($"{substiResult} is not a double"); } }
public static MathStatement ToDecimal2(string val) => decimal.TryParse(val, out decimal result) ? Dec.Create(result) : new Zero();
public MathStatement Substitute(Expr current, decimal replacement) { return(Substitute(current, Dec.Create(replacement))); }