This project contains a command line expression calculator. The application reads one line at a time from the command line and calculates a result. The result is printed to the screen. The main function is called Eval(). Eval() takes the math expression and does three operations: Tokenize(), InfixToPostFix() and EvalPostFix(). Use Copy and Paste (Ctrl-C and Shift-Insert) on the command line as needed.
The is a C# Console-Mode Project. Open with Visual Studio 2022 and above to compile.
Command-Line Calculator. Calculate one math expression per line.
Shell
RpnOne
Input File
RpnOne [inFile]
Input File is optional.
Help
RpnOne -h
Enter an empty line.
Unit Tests are included.
Operator | Description | Example |
---|---|---|
+ | Add | 1 + 2 |
- | Subtract | 5 - 2 |
* | Multiply | 2 * 7 |
/ | Divide | 30 / 3 |
% | Modulus | 15 % 3 |
^ | Power, a ^ b | 3 ^ 2 |
@ | Negate | -5 |
! | Factorial | 6! |
A | Asolute Value | A(-5) |
ACOS | Anti-Cosine | ACOS(0.3) |
ASIN | Anti-Sine | ASIN(0.4) |
ATAN | Anti-Tangent | ATAN(0.5) |
CB | Cube, a ^ 3 | CB(5) |
CDF | Cumulative Density Function | CDF(0.5) |
CL | Ceiling | CL(7.25) |
COS | Cosine in radians | COS(0.6) |
CR | Cube root, EXP(a, 1 / 3) | CR(15) |
DEG | Radians To Degrees | DEG(45) |
EN | Euler's Number 2.71 | EN |
F | Fraction | F(2.34) |
FL | Floor | FL(7.63) |
GCF | Greatest Common Factor | GCF(3, 21) |
I | Integer | I(72.34) |
LCM | Least Common Multiple | LCM(5, 125) |
LG | Base 10 Logarithm, 10 ^ a | LG(25) |
LN | Natural Logarithm, e ^ a | LN(35) |
NCR | Combinations | NCR(6, 2) |
ND | Normal Disribution | ND(0.25, 0, 1) |
NPR | Permutations | NPR(6, 2) |
P2 | Power of two, 2 ^ a | P2(6) |
PD | Prime Divisor | PD(55555) |
PI | Half rotation in radians 3.14 | PI |
R | Reciprocal, 1 / x | R(16.25) |
RAD | Degrees To Rdians | RAD(0.785) |
RAN | Random Integer | RAN |
RD | Round | RD(3.34) |
RND | Random Double Between One and Zero | RND |
RT | Nth Root, EXP(a, 1 / b) | RT(38, 4) |
S | Change Sign | S(-5) |
SIN | Sine in radians | SIN(0.83) |
SR | Square Root, SQRT(a) | SR(25) |
STU | Student T-Distribution | STU(1, 10) |
TAN | Tangent in radians | TAN(0.35) |
TAU | Full rotation in radians 6.28 | TAU |
X2 | Square, a * a | X2(3) |
X3 | Cube, a ^ 3 | X3(5) |
> 1 + 2
3
> 5 - 3
2
> 4 * 5
20
> ((44.3 * 55) + (2 * 5) - 33.3)
2413.2
> COS(RAD(45))
0.7071067811865476
> -2 * 5
-10
> -(2 * 5)
-10
> LCM(13342, 234334)
1563242114
> GCF(13342, 234334)
2
> 6 * PI
18.84955592153876
> EN
2.718281828459045
> 40-(1+2)
37
> RND
0.3398089438635673
Variables can be bound at the source code level. Use the Bind() function.
var str = "A * B - C";
Util util = new Util();
string result = util.Bind(str, "A", 22.1);
result = util.Bind(result, "B", 17.4);
result = util.Bind(result, "C", 66.45);
Assert.AreEqual("22.1 * 17.4 - 66.45", result);
1. James McCaffrey, "The Normal Cumulative Density Function in C#", http://jamesmccaffrey.wordpress.com, 2014.