Skip to content
arrow- edited this page May 6, 2016 · 2 revisions

#The liquid

liquid is a simple CLI math application that can solve simple math problems.

#How is the code organised?

This is the directory structure:

└── liquid
    ├── liquid.cpp
    ├── testing.cpp
    ├── shunting-yard.cpp
    ├── shunting-yard.h
    ├── Makefile
    └── src
        ├── math-lib.h
        ├── ml_add.cpp
        ├── ml_div.cpp
        ├── ml_mul.cpp
        ├── ml_sub.cpp
        ├── .
        ├── .
        ├── .
        └── ml_*****.cpp

We've already made the CLI which can be used to input a math expression and get the result.

Credit: @bmars for implementing the Shunting-Yard Algorithm in c. It's basically the RPN expression parser, which pushes into a stack to parse an expression and then evaluate based on priority rules by popping the stack.

The name of the CLI file is liquid.cpp. You don't have to edit liquid.cpp.

#What do I edit?

See the src/ directory? Read math-lib.h. This is the list of functions that provide the computational functionality to liquid.

double ml_add(double, double);
double ml_mul(double, double);
double ml_div(double, double);
double ml_sub(double, double);

But, except the add, mul, div, and sub, files, the rest are empty. And there's also a template file (ml_template.cpp).

#Operator Mapping

The operators have been listed in their precedence order, last row has least priority.

Precedence Symbol Operation Example
1 ! Factorial 4! >> 24
2 ^ Exponent 3^2 >> 9 fractional powers not suppoerted
3 + Unary_Positive_Symbol Trivial
3 - Unary_Negative_Symbol Trivial
4 P Permutation 10P3 >> 720
4 C Choose 10C3 >> 120
4 # GCD 343 # 21 >> 7
4 $ LCM 24 $ 21 >> 168
5 * Multiplication Trivial
5 / Division Trivial
5 % Modulus 657%14 >> 13
6 + Addition Trivial
6 - Subtraction Trivial
7 ( Parenthesis Trivial

###List of implemented Functions

abs() ln(), logarithm to the base e lb(), logarithm to the base 2 lg() / log(), logarithm to the base 10 sin() cos() tan() isPrime() factorise() nextPrime()

#Appendix

CLI Command Line Interface. It means a terminal is opened for the user, not a GUI.

Clone this wiki locally