Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/mistress' into github-page
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-extracts committed Nov 14, 2023
2 parents 1f330fd + 879196f commit 7cf887e
Show file tree
Hide file tree
Showing 17 changed files with 638 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mini-calc"
version = "2.1.1"
version = "2.2.2"
license = "GPL-3.0-or-later"
description = "A minimalistic configurable rust calculator"
homepage = "https://calc.nwa2coco.fr"
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ The page walking down the configuration of the project is available [here](docs/
- [X] Config
- [X] Config colours
- [X] Config prompt
- [ ] Add more operations
- [X] Add more operations
- [X] exponent
- [ ] Add support for functions
- [ ] exp
- [ ] ln
- [ ] log base a
- [ ] cos/sin/tan
- [ ] cosh/sinh/tanh
- [X] Add support for functions
- [X] exp
- [X] ln
- [X] log base a
- [X] cos/sin/tan
- [X] cosh/sinh/tanh
- [X] atan/acos/asin
- [ ] For later
- [ ] Defining your own functions
- [ ] Add RPN mode
Expand Down
Binary file added docs/assets/expln.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/trigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions docs/function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Functions

The following functions are available

Trigonometry
- sin
- cos
- tan

Hyperbolic trigonometry
- sinh
- cosh
- tanh

Reverse trigonometry
- asin
- acos
- atan

Exponentiation
- exp
- ln
- log (alias of ln)

## 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](assets/trigo.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](assets/expln.png)
30 changes: 16 additions & 14 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ cargo install mini-calc

You can see how the calculator works over at [the usage page](usage.md)

# Config
## Config

An overview of the configuration of mini-calc can be found [here](config.md)

## Function

An overview of the function of mini-calc can be found [here](function.md)

## TODO List

- [X] Lexing of basic operations
Expand Down Expand Up @@ -73,17 +77,17 @@ An overview of the configuration of mini-calc can be found [here](config.md)
- [X] Built-in
- [X] pi
- [X] e
- [ ] Config
- [ ] Config colours
- [ ] Config prompt
- [ ] Add more operations
- [X] Config
- [X] Config colours
- [X] Config prompt
- [X] Add more operations
- [X] exponent
- [ ] Add support for functions
- [ ] exp
- [ ] ln
- [ ] log base a
- [ ] cos/sin/tan
- [ ] cosh/sinh/tanh
- [X] Add support for functions
- [X] exp
- [X] ln
- [X] log base a
- [X] cos/sin/tan
- [X] cosh/sinh/tanh
- [ ] For later
- [ ] Defining your own functions
- [ ] Add RPN mode
Expand All @@ -101,6 +105,4 @@ An overview of the configuration of mini-calc can be found [here](config.md)

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

![](docs/assets/test_interpreter.png)

## Configuration
![](docs/assets/test_interpreter.png)
6 changes: 2 additions & 4 deletions src/configuration/loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use ansi_term::{ANSIGenericString, Color};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -74,7 +72,7 @@ pub fn load_rgb_color(str: &str) -> (u8, u8, u8) {

let r = match rd {
Ok(c) => c,
Err(e) => 0xFF,
Err(_) => 0xFF,
};

let g = match gd {
Expand Down Expand Up @@ -121,7 +119,7 @@ pub fn load_color(string: String) -> Color {

pub fn replace_variable(str: String) -> String {
str.replace("%author%", "Charlotte Thomas")
.replace("%version%", "v2.2.2")
.replace("%version%", "v2.3.0")
.to_string()
}

Expand Down
30 changes: 30 additions & 0 deletions src/interpreting/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub fn add(i: Parameters, i2: Parameters, ram: Option<&HashMap<String, Parameter
(Parameters::Identifier(s), Parameters::Int(i)) => {
apply_operator(Parameters::Identifier(s), Parameters::Int(i), ram, add)
}
(Parameters::Null, Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, add)
}
(Parameters::Identifier(s), Parameters::Null) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, add)
}
(Parameters::Int(i), Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Int(i), ram, add)
}
Expand Down Expand Up @@ -107,6 +113,12 @@ pub fn minus(
(Parameters::Identifier(s), Parameters::Int(i)) => {
apply_operator(Parameters::Identifier(s), Parameters::Int(i), ram, minus)
}
(Parameters::Null, Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, minus)
}
(Parameters::Identifier(s), Parameters::Null) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, minus)
}
(Parameters::Int(i), Parameters::Identifier(s)) => {
let v = apply_operator(Parameters::Identifier(s), Parameters::Int(i), ram, minus);
match v {
Expand Down Expand Up @@ -154,6 +166,12 @@ pub fn mult(
(Parameters::Int(i), Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Int(i), ram, mult)
}
(Parameters::Null, Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, mult)
}
(Parameters::Identifier(s), Parameters::Null) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, mult)
}
(Parameters::Identifier(s), Parameters::Float(i)) => {
apply_operator(Parameters::Identifier(s), Parameters::Float(i), ram, mult)
}
Expand Down Expand Up @@ -194,6 +212,12 @@ pub fn divide(
_ => Parameters::Null,
}
}
(Parameters::Null, Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, divide)
}
(Parameters::Identifier(s), Parameters::Null) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, divide)
}
(Parameters::Identifier(s), Parameters::Float(i)) => {
apply_operator(Parameters::Identifier(s), Parameters::Float(i), ram, divide)
}
Expand Down Expand Up @@ -237,6 +261,12 @@ pub fn expo(
(Parameters::Identifier(s), Parameters::Float(i)) => {
apply_operator(Parameters::Identifier(s), Parameters::Float(i), ram, expo)
}
(Parameters::Identifier(s), Parameters::Null) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, expo)
}
(Parameters::Null, Parameters::Identifier(s)) => {
apply_operator(Parameters::Identifier(s), Parameters::Null, ram, expo)
}
(Parameters::Float(i), Parameters::Identifier(s)) => {
apply_operator_reverse(Parameters::Float(i), Parameters::Identifier(s), ram, expo)
}
Expand Down
6 changes: 6 additions & 0 deletions src/interpreting/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use crate::interpreting::function::{add, assign, divide, expo, minus, mult};
use crate::interpreting::stdlib::exec;
use crate::parsing::ast::{Ast, Parameters};

pub fn interpret(ast: Ast, mut ram: &mut HashMap<String, Parameters>) -> Parameters {
Expand Down Expand Up @@ -29,10 +30,15 @@ pub fn interpret(ast: Ast, mut ram: &mut HashMap<String, Parameters>) -> Paramet
Parameters::Float(f) => Parameters::Float(f),
Parameters::Int(i) => Parameters::Int(i),
Parameters::Identifier(s) => Parameters::Identifier(s),
Parameters::Call(s) => Parameters::Identifier(s),
Parameters::Null => Parameters::Null,
};
last.clone()
}
Ast::Call { name: n, lst: list } => {
let v: Vec<Parameters> = list.iter().map(|x| interpret(x.clone(), ram)).collect();
exec(n, v, Some(&ram))
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/interpreting/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod function;
pub(crate) mod interpreter;
mod stdlib;
Loading

0 comments on commit 7cf887e

Please sign in to comment.