Calc

Calc: a fully-featured minimalistic calculator built in rust for educational purpose only.

Install

You can install the latest version from source

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

or install it via cargo

cargo install mini-calc

Usage

You can see how the calculator works over at the usage page

Config

An overview of the configuration of mini-calc can be found here

Function

An overview of the function of mini-calc can be found here

Logic

To learn about the binary logic built in go to the logic page

Plot !

You can plot more information in the plot page

User defined functions

You can define your own functions!

img.png

Vector calculation

You can compute using vectors!

  • add vectors
  • dot product (* operator)
  • norm function

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.2 the matrices are pretty-printed!

Non interactive use !

As of 2.12.2 you can use the calculator without the REPL!

Usage

you use it as a regular calculator

Basic Operators

  • + for the addition
  • - for the subtraction
  • / for the division
  • * for the multiplication
  • ^ for the exponentiation

Setting variable

It's easy to set a variable, just use

myvar = value

example:

myvar = (2+2)

Built-in variable

  • pi is pi as a double precision float
  • e is e as a double precision float

Functions

The following functions are available

Trigonometry

  • sin (vectorized)
  • cos (vectorized)
  • tan (vectorized)

Hyperbolic trigonometry

  • sinh (vectorized)
  • cosh (vectorized)
  • tanh (vectorized)

Reverse trigonometry

  • asin (vectorized)
  • acos (vectorized)
  • atan (vectorized)

Exponentiation

  • exp (vectorized)
  • ln (alias: log) (vectorized)

Vectors

  • norm

Matrices

  • det
  • invert

Plot

  • plot
  • termplot

Other

  • sqrt (vectorized)
  • factorial (aliases: fact or !)
  • 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

Partial function

The language supports partial function

img.png

Vectorization

Function has been vectorized, for example

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.

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

Interact in the command line

You can interact and modify the config from the command line the commands are

  • config: show the current config
  • config reload: reload the config
  • config reset: reset the config to default parameters
  • config set

categories are :

  • greeting_message
  • greeting_color
  • prompt_color
  • prompt
  • general_color

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

Plot

You can plot, backend is provided by GNUPlot, so it should work great on linux and macos but behiaviour on windows is not known.

Help

To display the help just type help

Plot

Default

It's easy to plot a function by default, just type plot(fn)

Options

A more difficult plot can be ploted by adding parameters

Plot your own function

You can plot your function!

Terminal plotting

You can plot right into the terminal!

Default

The best example to show it is the square function between -5 and 5 with a 0.1 step. The x axis is automatically scaled but not the y axis for now.

With option

The terminal supports options!

Auto y scaling

Now the y axis auto scales, and labels were added in 2.9.2 !

Exact Math

Rational exact math

As of 2.11.0 rational exact math was added, support for

  • Rational operation
  • Rational reduction

Was added.

It was also added to the stdlibs for the functions.

Example

Or even with inverse of matrices!

And it rationalize floats with 10 decimal points of precision (but printed as 5)