Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

calc

A command-line calculator written in Rust. Evaluates mathematical expressions with support for arithmetic, trigonometry, implicit multiplication, and operator precedence.

Install

cargo build --release

Usage

Interactive mode:

cargo run

Type expressions at the -> prompt. Type quit or exit to stop.

One-shot mode:

cargo run -- -c "2+3*4"

Debug mode (shows the full evaluation pipeline):

cargo run -- -c "sin(45deg)" debug

Examples

-> 2+3*4
14
-> (2+3)*4
20
-> 2(3+1)
8
-> -5+3
-2
-> sin(45deg)
0.7071067811865475
-> 2^10
1024

Supported Operations

Operation Syntax
Addition a + b
Subtraction a - b
Multiplication a * b
Division a / b
Power a ^ b
Trig (sin, cos, tan, cot, sec, cosec) sin(expr)
Degree mode sin(45deg)
Radian mode sin(pi rad)
Parentheses (expr)
Implicit multiplication 2(3) = 2*(3)

Building

cargo build              # debug build
cargo build --release    # optimized release build
cargo check              # type-check only
cargo clean              # remove build artifacts

Project Structure

src/
  main.rs      -- CLI parsing, REPL loop
  eval.rs      -- Lexer, parser, infix-to-postfix, evaluator
  tokens.rs    -- Token definitions and operator precedence
  utils.rs     -- Input utilities

About

Simple cli calculator using rust

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages