https://github.com/techno-coder/calculator
Multipurpose calculator with coalescing written in Rust
https://github.com/techno-coder/calculator
calculator coalescence rust
Last synced: 3 months ago
JSON representation
Multipurpose calculator with coalescing written in Rust
- Host: GitHub
- URL: https://github.com/techno-coder/calculator
- Owner: Techno-coder
- License: mit
- Created: 2019-10-20T04:36:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-29T07:37:21.000Z (over 5 years ago)
- Last Synced: 2025-03-18T17:08:01.211Z (3 months ago)
- Topics: calculator, coalescence, rust
- Language: Rust
- Size: 143 KB
- Stars: 22
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# calculator

```
>> (10) - 2 + 4;
[0] 4
>> 2 * 0x03
[1] 6
>> $ ^ $$
[2] 1296
>> $2 % 5
[3] 1
```## Installation
```
$ cargo install --locked --git https://github.com/Techno-coder/calculator
```## Execution
```
$ calculator
```
Basic mode does not update on each key press and may work better for less
advanced terminals.
```
$ calculator -b/--basic
```
Evaluation mode reads from the standard input pipe and outputs results directly.
```
$ echo expression | calculator -e/--evaluation
```## Arithmetic Operators
In order of precedence:
* `+` - Add
* `-` - Minus
* `*` - Multiply
* `/` - Divide
* `%` - Modulo
* `^` - Power## Numerical Formats
* `0x000a` - Hexadecimal
* `0b1010` - Binary
* `0o0012` - Octal
* `1.0` - Floating
* `1e1` - Scientific## Variables
* `$` - Last evaluation result
* `$$` - Second last evaluation result
* `$$...$` - Arbitrary position evaluation result
* `$0` - Variable with identifier `0`
* `$aa` - Variable with identifier `aa`## Functions
```
>> function argument
```
Functions take the term immediately to the right.
Whitespace is required after the function name.* `abs` - Absolute value
* `sqrt` - Square root
* `cbrt` - Cube root
* `ln` - Natural logarithm
* `log2` - Binary logarithm
* `log10` - Decimal logarithm### Trigonometry
* `sin` - Sine
* `cos` - Cosine
* `tan` - Tangent
* `asin` - Inverse sine
* `acos` - Inverse cosine
* `atan` - Inverse tangentThe trigonometric functions can take and return degrees by appending `'`:
```
>> asin' 1
[0] 90
```## Constants
* `e` - Euler number
* `pi` - Pi (3.14)## Coalescence
* `;` - Coalesce operatorThe coalesce operator combines the previous two terms into a single node.
This eliminates the need for parentheses.```
>> 10 - 2 + 4;
```
is equivalent to:
```
>> 10 - (2 + 4)
```Repetitions of the coalesce operator will combine more than two terms:
```
>> 1 / 1 + 2 + 3;;
```
is equivalent to:
```
>> 1 / (1 + 2 + 3)
```
Sometimes a combined term is nested inside another:
```
>> 1 / (2 - (3 + 4))
```
This can be achieved by leaving whitespace after the first coalescence:
```
>> 1 / 2 - 3 + 4; ;
```