https://github.com/astrodynamic/arithmetic-calculations-in-c-for-calculator
Library for arithmetic string calculator in C.
https://github.com/astrodynamic/arithmetic-calculations-in-c-for-calculator
c calculator cmake library makefile math parser
Last synced: 3 days ago
JSON representation
Library for arithmetic string calculator in C.
- Host: GitHub
- URL: https://github.com/astrodynamic/arithmetic-calculations-in-c-for-calculator
- Owner: Astrodynamic
- License: mit
- Created: 2023-05-05T12:30:09.000Z (about 3 years ago)
- Default Branch: develop
- Last Pushed: 2023-05-05T12:39:20.000Z (about 3 years ago)
- Last Synced: 2025-03-02T05:27:47.746Z (over 1 year ago)
- Topics: c, calculator, cmake, library, makefile, math, parser
- Language: C
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Arithmetic calculation Library
This library provides functionality for arithmetic calculations in string calculator for C language.
## Build
To build the library, please follow the steps below:
1. Clone the repository
2. Run `make` in the project directory.
## Usage
After building the library, you can use it by including the `calculation.h` header file and calling the `calculation` function in your C code. The `calculation` function takes a deque of lexemes in Reverse Polish Notation and a double value for the variable `x`, and returns a double value which is the result of the calculation.
## Dependencies
This library depends on the following libraries:
* C Standard Library
* Math Library
## Development
To contribute to this library, please follow the steps below:
1. Clone the repository
2. Run `make` in the project directory to build the library.
3. Make changes to the source code.
4. Run `make` again to rebuild the library.
5. Test your changes.
6. Submit a pull request.
## License
This library is licensed under the [MIT LICENSE](LICENSE).
## Example Build and Usage
Assuming the library is built as `ArithmeticCalculation.a` and the following code is in a file named `main.c`.
```c
#include
#include "calculation.h"
int main() {
lexeme_t *lexemes = NULL;
Deque *rpn = init_deque();
// populate lexemes and rpn with appropriate values
double result = calculation(rpn, 5.0);
printf("Result: %lf\n", result);
return 0;
}
```
To compile and link the code with the library:
```bash
$ gcc -c main.c -o main.o
$ gcc main.o -L. -ArithmeticCalculation -o calculator
```
This will create an executable named `calculator`. Running it will print the result of the calculation.
```bash
$ ./calculator
Result: 25.000000
```