39 stable releases

3.2.0 Jun 5, 2024
3.1.0 May 26, 2024
2.13.2 May 14, 2024
2.13.1 Apr 23, 2024
1.0.0 Nov 12, 2023

#23 in Visualization

Download history 199/week @ 2024-07-27 32/week @ 2024-09-21 6/week @ 2024-09-28

2,411 downloads per month

GPL-3.0-or-later

320KB
9K SLoC

Calc

Calc: A fully-featured minimalistic configurable rust calculator

Rust Test Release

Install

Source

You can install the latest version from source

git clone https://github.com/coco33920/calc
cd calc
cargo build --release
./target/release/mini-calc

Cargo

cargo install mini-calc

using Nix

Alternatively, you can use nix to build or run this project.

Running directly:

nix run github:coco33920/calc

You may need to enable nix experimental features. In that case, execute the following command: mkdir -p ~/.config/nix && echo "experimental-features = nix-command flakes" | tee ~/.config/nix/nix.conf

From packaged version

Both .deb and .rpm packages are availables in the

Website

The website (powered by oranda) is available for more informations the website for more informations.

Manual

If you prefer a PDF, there is a manual

Contributors

Name Role Website
Charlotte THOMAS Main developer/Maintener Main page
Léana 江 Help, cleanup Website/Blog
Sigmaficient Nixify Website

TODO List

The TODO list is completed so I collapsed it

TODO List
  • Lexing of basic operations
    • Lexing operators
    • Lexing lpar,rpar,quote
    • Lexing int
    • Lexing floats
    • Lexing identifiers
  • Parsing of basic operations
    • Parsing int,floats,identifiers
    • sum operation
    • minus operation
    • multiplication operation
    • division operation
  • Parsing advanced operations
    • Parsing lpar,rpar
    • mathematical priority
      • Left priority
      • Right priority
    • parenthesis support
    • Assignment
    • associativity support
      • Left associativity
      • Right associativity
  • Application REPL
    • Add the REPL
      • basic REPL
      • colour message
      • colourised prompt
    • Add colour
  • Interpreter
    • Basic operation interpreter
    • Advanced operation interpreter
    • Identifiers (variable) interpreter
  • Built-in
    • pi
    • e
  • Config
    • Config colours
    • Config prompt
  • Add more operations
    • exponent
  • Add support for functions
    • exp
    • ln
    • log base a
    • cos/sin/tan
    • cosh/sinh/tanh
    • atan/acos/asin
  • Add logic
    • Add basic true/false
    • Add binary operator
      • or (&&)
      • and (||)
      • >=
      • >
      • <=
      • <
      • ==
    • Add unary operator
      • not (!)
  • Vector calculation
    • Add vectors to the datatypes
    • Lex vectors
    • Parse vectors
    • Add vector operations
      • Dot product
      • Vector norm
      • Vector addition
  • Matrix calculation
    • Add matrix to the datatypes
    • Lex matrices
    • Parse matrices
    • Add matrices operation
      • Matrix addition
      • Matrix multiplication
      • Calculate the matrix determinant
      • Calculate the reverse matrix
  • Interact with the configuration
    • Print current config
    • Reset config to default
    • [X] Set config
      • Set main color
      • Set prompt color
      • [X] Set prompt
      • Set greeting message
      • [X] Set greeting color
    • [X] Reload config

Evolution

Ploting

Plot functions (both stdlib, and runtime) would be useful and appreciated. Plotting is powered by gnuplot, it will works on Unix-like (MacOS, Linux) but I don't have any idea about Windows

  • Plot stdlib functions

  • [X] Plot runtime functions

  • Save plot to png/svg/pdf

  • Add terminal ploting

    • Calculate ploting height and width
    • Computes individual points
    • Generate each line
    • Prints each line
  • Auto level x axis in termplot

  • Auto level y axis in termplot

Example of plotting

You can plot function defined in the standard library of calc or user defined functions, to display the help just type plot()

You can then plot for example

Plotting cos with the default values (from 0 to 3pi, with a step of 0.01pi)

Plotting sin with custom values (from -pi to pi, with a step of 0.01rad, with line, title, x label, y label)

Defining f(x) = x² and plotting it with custom values (from -10 to 10, with a step of 0.1, with linespoint)

Example of terminal plotting

You can plot in the terminal, for example

And it supports the labels too

And now it auto scales on y!

Exact math calculator

As this project provides a frontend with a parser we could plug an exact math engine in the backend to transform calc into a real exact math calculator. TODO List for the Exact Math Engine

  • Rational calculation
    • Implement rational numbers operations
    • Rational reduction
  • Literal calculation
    • Computes literal expression with uninitialized operators
    • Literal reduction
  • Irrational calculation
    • Implement irrational numbers operations
    • Irrational reduction

Example of rational computations

As of 2.11.0 the support for rational exact math has been implemented

As of 2.11.1 it works in matrices!

As of 2.11.4 floats are automatically rationalized (with 10 decimal points of precision)

CAS

If we ever go to this step, yes, I will remove the "minimalistic" from the description

  • It's hard.

Examples

REPL with only Lexing (verbose mode: on by default)

REPL with lexing and basic operation parsing (verbose mode: on by default)

REPL and functionning interpreter (verbose mode: off by default)

Configuration

You can configure the general color, greeting message, greeting color, prompt and prompt color from the file for example in (for linux)

~/.config/mini-calc/mini-calc.toml

Or situated in your operating system config folder.

You can interact with the configuration with the command line, more info in the web page

What the configuration looks like

The default configuration looks like this

img.png

Colors

Available colors are

  • purple
  • cyan
  • blue
  • black
  • red
  • yellow
  • green
  • white
  • an hexadecimal colour (ex: "#f7a8d8")

Default colour (if the configuration fail to load) is Cyan.

Example of a modified configuration

Configuration:

img.png

It looks like:

img.png

Functions

The following functions are available

  • sin
  • cos
  • tan
  • sinh
  • cosh
  • tanh
  • asin
  • acos
  • atan
  • exp
  • ln (alias: log)
  • sqrt
  • factorial (alias: fact)
  • abs
  • ceil
  • floor
  • round

Trigonometry

For trigonometry, the input are assumed to be in radian, if not, you have to put "false" or "true" as second argument, example shown bellow

img.png

Exp/ln

If you use the exp function you can pass a second argument for the base you are using, if no second arguments are passed this is assumed to be in natural base

img.png

Root

You can take the nth root with the sqrt function, by default it takes the second root.

img.png

Round

You can round to the nth decimal with the round function, by default it round to the integer (floor)

img.png

Vectorization

Function are now vectorized! Just pass a vector as an argument!

Logic

You can now use logic! I implemented the following functions:

  • or (alias : ||)
  • and (alias : &&)
  • geq (alias : >=)
  • gt (alias : >)
  • leq (alias : <=)
  • lt (alias :<)
  • eq (alias : ==)

Example:

img.png

User defined functions!

You can define your own functions!

img.png

Vector calculation !

You can use vectors!

  • add vector to each others
  • added the norm function to compute the norm
  • dot product between two vectors ( * operator)

Functions added:

  • norm

Matrices !

As of 2.7.0 matrix algebra is implemented (using lup reduction)

  • you can add matrices
  • multiply compatible matrices

functions added

  • transpose
  • invert
  • det

As of 2.11.3 matrices are pretty printed !

Non interactive use

As of 2.12.0 non interactive use was added

Dependencies

~7.5MB
~162K SLoC