From f63f1eccba51ffa0b8ed9a50850b4d5f62102a08 Mon Sep 17 00:00:00 2001 From: Miroiu Emanuel Date: Sat, 1 Feb 2020 14:23:29 +0200 Subject: [PATCH] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 979acfd..a9bb0b9 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Calculates the value of a math expression from a string returning a decimal. Supports variables and user defined operators. +### Creating and using a calculator ```csharp -// Evaluating a simple expression Calculator myCalculator = new Calculator(); decimal result = myCalculator.Evaluate("1 * (2 - 3) ^ 2"); // 1 @@ -16,8 +16,8 @@ myCalculator.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power); decimal result = myCalculator.Evaluate("2 * 3 max 4"); // 8 ``` -```csharp -// Using a variables collection +### Creating and using variables +```csharp Replacements variables = new Replacements { ["a"] = 5, @@ -32,8 +32,9 @@ myCalculator.Replace("b", 1); decimal result = calculator.Evaluate("{a} + 2 * {b} + {PI}"); // 7.1415926535897931 ``` +### Using the static api: SMath ```csharp -// Using the static class SMath +// Same API as a calculator instance except the Evaluate method decimal result = SMath.Evaluate("1 + 1"); // 2 decimal result = SMath.Evaluate("1 + {myVar}", new Replacements { ["myVar"] = 1 }); // 2 ```