Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
miroiu authored Feb 1, 2020
1 parent 5c8c348 commit f63f1ec
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
```

0 comments on commit f63f1ec

Please sign in to comment.