tc-calc/README.md

50 lines
838 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# tc-calc
Our built-in calculator. This is the REPL loop used by Terminal Click.
## Build Instructions
`cc main.c -o calc -lm`
Where `cc` is our C compiler e.g. `gcc`, `clang`, `zig cc`.
## How to Use
### Single Eval
Run the executable with `-e` flag to evaluate a single expression and exit.
```sh
./calc -e "3.14**2"
9.8596
```
### REPL
Run the executable `calc` to be greeted with the following prompt:
`calc>`
Now we type any valid arithmetic expression as we would in a Python REPL:
```
calc> (2+2)*(2+2)
16
calc>
```
Notice how we print the output with a bit of spacing followed by a new prompt.
**Switching Formats**
We can switch between decimal, hexadecimal and binary formats. Use the `:dec`, `:hex`, or `:bin` tags:
```
calc> :hex
format: hex
calc> 0xA - 0x9
0x1
calc>
```
The default tag is `:dec`.