Skip to content

Commit acc1bc4

Browse files
committed
Merge branch 'develop'
2 parents 717c1f4 + 0c35562 commit acc1bc4

16 files changed

+1189
-1181
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to **antlr-calculator** are documented here.
44

5+
## v2.2.0:
6+
- Added support for `Min` and `Max` formulas
7+
58
## v2.1.0:
69
- The calculator now supports trailing comments in a formula, separated by a semicolon `;` at the end of the actual formula input. For example, `1 + 2; Hello World!` now just evaluates `1 + 2` and ignores everything after the semicolon `;`
710
- Add support for substitutions in formulas

README.md

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ to calculate results from formulas that are passed in as string. Both JavaScript
99
Whenever a calculation is performed, a `CalculationResult` is returned with the following properties:
1010

1111
| Property | Type | |
12-
|---------------|---------|---------------------------------------------------------------------------------------------|
12+
| ------------- | ------- | ------------------------------------------------------------------------------------------- |
1313
| isValid | boolean | `true` if the formula could be parsed and calculated, else `false` |
1414
| errorPosition | number | Position of the offending symbol in the line, 0 based index, for invalid results, else null |
1515
| errorMessage | string | ANTLR error message for invalid formulas, else null |
@@ -26,9 +26,8 @@ Clone this repository or just go with `npm install antlr-calculator`.
2626
## JavaScript
2727

2828
Just reference `dist/bundle.js` and the global variable `antlrCalc` is available.
29-
3029

31-
``` javascript
30+
```javascript
3231
var result = antlrCalc.Calculator.calculate('4*5');
3332
console.log(JSON.stringify(result, null, 2));
3433

@@ -38,14 +37,13 @@ console.log(JSON.stringify(result, null, 2));
3837
// "errorMessage": null,
3938
// "result": 20
4039
// }
41-
4240
```
4341

4442
## TypeScript
4543

4644
Import the `Calculator` class and use the static `calculate(formula: string)` method to evaluate formulas.
4745

48-
``` typescript
46+
```typescript
4947
import { Calculator } from 'antlr-calculator';
5048

5149
var result = Calculator.calculate('4*5');
@@ -61,50 +59,52 @@ console.log(JSON.stringify(result, null, 2));
6159

6260
## Supported functions
6361

64-
| Expression | |
65-
|------------------------------------------|---------------------------------------|
66-
`FLOOR expression` | Round down to zero accuracy |
67-
`CEIL expression` | Round up to zero accuracy |
68-
`ABS expression` | Absolute value |
69-
`ROUNDK '(' expression ';' expression ')'` | Round expr_1 with expr_2 accuracy |
70-
`ROUND expression` | Round with zero accuracy |
71-
`TRUNC expression` | Trim decimal digits |
72-
`SIN expression` | Sinus |
73-
`COS expression` | Cosinus |
74-
`TAN expression` | Tangens |
75-
`COT expression` | Cotangens |
76-
`SINH expression` | Sinus Hypererbolicus |
77-
`COSH expression` | Cosinus Hyperbolicus |
78-
`TANH expression` | Tangens Hyperbolicus |
79-
`ARCSIN expression` | Inverse Sinus |
80-
`ARCCOS expression` | Inverse Cosinus |
81-
`ARCTAN expression` | Inverse Tangens |
82-
`ARCTAN2 '(' expression ';' expression ')'`| Atan2 |
83-
`ARCCOT expression` | Inverse Cotangens |
84-
`EXP expression` | e ^ expr |
85-
`LN expression` | Logarithm to e |
86-
`EEX expression` | 10 ^ expr |
87-
`LOG expression` | Logarithm to 10 |
88-
`RAD expression` | Angle to radians (360° base) |
89-
`DEG expression` | Radians to angle (360° base) |
90-
`SQRT expression` | Square root |
91-
`SQR expression` | Square product |
92-
`expression op = ('^'|'**') expression` | expr_1 to the expr_2 th power |
93-
`expression (MOD | '%' ) expression` | Modulo |
94-
`expression DIV expression` | Whole part of division rest |
95-
`expression op = ('~'|'//') expression` | expr_1 nth root of expr_2 |
96-
`expression op = ('*'|'/') expression` | Multiplication or division |
97-
`expression op = ('+'|'-') expression` | Addition or subtraction |
98-
`NUMBER ` | Single integer or float number |
99-
`'(' expression ')'` | Expression within parentheses |
100-
`PI '()'?` | Mathematical constant pi = 3,141593 |
101-
`expression E+ expression` | Exponent, e.g. 10e+43 |
102-
`expression E- expression` | Inverted Exponent, e.g. 10e-43 |
103-
`EULER` | Mathematical constant e = 2,718282 |
104-
`'-' expression` | Unary minus sign (negative numbers) |
105-
`'+' expression` | Unary plus sign (positive numbers) |
106-
`'(' expression ')' expression` | Expressions without multiplication sign, e.g. `2(3)` -> `2*(3)` |
107-
`expression '(' expression ')'` | Expressions without multiplication sign, e.g. `2(3)` -> `2*(3)` |
62+
| Expression | |
63+
| ------------------------------------------- | --------------------------------------------------------------- | ----------------------------- |
64+
| `FLOOR expression` | Round down to zero accuracy |
65+
| `CEIL expression` | Round up to zero accuracy |
66+
| `ABS expression` | Absolute value |
67+
| `ROUNDK '(' expression ';' expression ')'` | Round expr_1 with expr_2 accuracy |
68+
| `ROUND expression` | Round with zero accuracy |
69+
| `TRUNC expression` | Trim decimal digits |
70+
| `SIN expression` | Sinus |
71+
| `COS expression` | Cosinus |
72+
| `TAN expression` | Tangens |
73+
| `COT expression` | Cotangens |
74+
| `SINH expression` | Sinus Hypererbolicus |
75+
| `COSH expression` | Cosinus Hyperbolicus |
76+
| `TANH expression` | Tangens Hyperbolicus |
77+
| `ARCSIN expression` | Inverse Sinus |
78+
| `ARCCOS expression` | Inverse Cosinus |
79+
| `ARCTAN expression` | Inverse Tangens |
80+
| `ARCTAN2 '(' expression ';' expression ')'` | Atan2 |
81+
| `ARCCOT expression` | Inverse Cotangens |
82+
| `EXP expression` | e ^ expr |
83+
| `LN expression` | Logarithm to e |
84+
| `EEX expression` | 10 ^ expr |
85+
| `LOG expression` | Logarithm to 10 |
86+
| `RAD expression` | Angle to radians (360° base) |
87+
| `DEG expression` | Radians to angle (360° base) |
88+
| `SQRT expression` | Square root |
89+
| `SQR expression` | Square product |
90+
| `expression op = ('^' | '\*\*') expression` | expr_1 to the expr_2 th power |
91+
| `expression (MOD | '%' ) expression` | Modulo |
92+
| `expression DIV expression` | Whole part of division rest |
93+
| `expression op = ('~' | '//') expression` | expr_1 nth root of expr_2 |
94+
| `expression op = ('\*' | '/') expression` | Multiplication or division |
95+
| `expression op = ('+' | '-') expression` | Addition or subtraction |
96+
| `NUMBER ` | Single integer or float number |
97+
| `'(' expression ')'` | Expression within parentheses |
98+
| `MIN '(' expression (';' expression)* ')'` | Minimum |
99+
| `MAX '(' expression (';' expression)* ')'` | Maximum |
100+
| `PI '()'?` | Mathematical constant pi = 3,141593 |
101+
| `expression E+ expression` | Exponent, e.g. 10e+43 |
102+
| `expression E- expression` | Inverted Exponent, e.g. 10e-43 |
103+
| `EULER` | Mathematical constant e = 2,718282 |
104+
| `'-' expression` | Unary minus sign (negative numbers) |
105+
| `'+' expression` | Unary plus sign (positive numbers) |
106+
| `'(' expression ')' expression` | Expressions without multiplication sign, e.g. `2(3)` -> `2*(3)` |
107+
| `expression '(' expression ')'` | Expressions without multiplication sign, e.g. `2(3)` -> `2*(3)` |
108108

109109
_expression_ may be any expression as functions can be nested. Example: `DEG(2*PI)` or `LOG(10^3)`.
110110

@@ -127,15 +127,13 @@ The calculator can be called with an overload that accepts a callback function f
127127
Here, `#Z4` is a _substitution_, which is a placeholder that can be externally supplied. Let's say you want to resolve `#Z4` to the value three, you could make this simple call:
128128

129129
```typescript
130-
const formula = "1,2*#Z4+3";
131-
const result = Calculator.calculate(formula, substitution =>
132-
{
133-
if (substitution === "#Z4")
134-
{
135-
return 3;
136-
}
137-
138-
return null;
130+
const formula = '1,2*#Z4+3';
131+
const result = Calculator.calculate(formula, (substitution) => {
132+
if (substitution === '#Z4') {
133+
return 3;
134+
}
135+
136+
return null;
139137
});
140138
```
141139

build/Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected override void OnTargetFailed(string target)
6161
{
6262
if (IsServerBuild)
6363
{
64-
SendTeamsMessage("Build Failed", $"Target {target} failed for Dangl.Calculator, " +
64+
SendTeamsMessage("Build Failed", $"Target {target} failed for antlr-calculator, " +
6565
$"Branch: {GitRepository.Branch}", true);
6666
}
6767
}

0 commit comments

Comments
 (0)