Skip to content

Vincent4486/Calculators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

                                The Calculators

The calculators project is the way I use to explore new programming languages,
since creating a calculator requires me to understand the concepts of reading
and writing to streams, error handling, and more.

In this project, I will implement calculators in the programming languages I
can think of using the following standards. I will not use an LLM to write any
code for this project, as it is intended for my own exploration.

Use this project at your own risk, as it could contain unfinished features and
bugs. You are welcome to open issues about the code on GitHub, but I will not
be accepting pull requests that change the source code.

                                   Standards

Modes
Each calculator must contain two modes, determined based on arguments:

- Argument mode: Specifies the expression in arguments; used when arguments are
  detected in `argv`.
- Interactive mode: Expressions are entered after the program starts or piped 
  to `stdin`. Used when no arguments are added.

Tokenization
All calculators should support expressions separated by spaces (e.g., 1 + 1 / 2)
or combined (e.g., 1+1/2). This requires tokenization when expressions are in 
combined mode.

Calculation Order
This calculator supports multi-step expressions like `1+1/2` where the 
calculator will first handle division and then addition. This will be achieved
mostly using array lists or other compound data types.

Variables
Both environment variables and local variables within the calculator can be 
accessed via their names with a `$` prefix. Standard variables like `pi` 
should be pre-defined locally.

History Saving & Keyboard Input Manipulation
All calculations made will be stored in the file `~/.calchistory`. This will 
only be written when the application quits. If the user presses the up or down
arrow keys, the application will intercept the keystroke and append the 
history.

Error Handling
When syntax errors or illegal operations are detected, the application will 
throw an exception—usually to the language's native error handling system. 
If none exists, it will be self-handled.

Signal Handling
The calculators should handle `SIGINT` to quit the application and write the 
calculation history.

Advanced Mathematical Operations
The calculators should support a variety of advanced mathematical operations 
such as `sin()` and `tan()`. Use of the program's mathematical library is 
allowed. The syntax for these matches standard function calls, such as 
`tan(1+2)`.

                                 Current Status

Languages Implemented
- C++: Full support
- Swift: Intermediate support
- Rust: Intermediate support

Languages Planned
- Java
- C
- Python

About

This is a terminal calculator written in C++, which supports advanced math calculations like cos and history managment. This is one of the calculators in my ConsoleCalculator series, and this has the most features.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors