Skip to content

Commit 904c799

Browse files
Merge branch 'mistress' into website
2 parents 6fdcc21 + 79e94f2 commit 904c799

File tree

11 files changed

+53
-39
lines changed

11 files changed

+53
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Version 3.3.4 : Bug fix
2+
Fix bug #61 and #59
3+
14
# Version 3.3.2 : CI
25

36
# Version 3.3.0 : Colours

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mini-calc"
3-
version = "3.3.3"
3+
version = "3.3.4"
44
license = "GPL-3.0-or-later"
55
description = "A Fully-Featured Configurable (mini) Rust Calculator"
66
homepage = "https://calc.charlotte-thomas.me"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
watch:
2-
cargo watch -x check -x fmt -x run
2+
cargo watch -x fmt -x run
33
compile:
44
cargo build
55
release:

manual.pdf

-2.88 KB
Binary file not shown.

manual/main.pdf

-2.88 KB
Binary file not shown.

manual/main.typ

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#import "@preview/codly:1.0.0": *
2+
#import "@preview/colorful-boxes:1.4.1": *
3+
24
#set page(numbering: "1/1")
35
#set align(center)
46
#set text(font: "Monaspace Xenon")
@@ -100,6 +102,14 @@ Visit #calc to see all the install page
100102
- `/` for the division (or for a rational)
101103
- `^` for the exponentation
102104

105+
#colorbox(
106+
title: "Warning",
107+
color: "red",
108+
)[
109+
You shoudln't use the `^` operator with functions, it is not taken into
110+
account for differentiations
111+
]
112+
103113
== Variables
104114

105115
It also supports variable the syntax is
@@ -492,12 +502,13 @@ As of `3.2.0`, the calculator can differentiate known functions (function
492502
constructed using the standard functions). It supports both built-in and
493503
user-defined functions.
494504

495-
#text(20pt)[#emoji.warning] Beware as of `3.3.3` there is some bugs to iron out.
505+
#colorbox(title: "Warning", color: "red")[Beware as of `3.3.3` there is some bugs to iron out.
496506
It doesn't differentiates vars (differentiation of $x*x$ works but not $x^2$.).
497507
And differentiation of function
498-
referencing each other (example $v(x) = f(x) + x*x$) doesn't work either.
508+
referencing each other (example $v(x) = f(x) + x*x$) doesn't work either.]
499509

500-
It's currently being fixed, and will be fixed before `3.4.0`
510+
#colorbox(title: "Fixed", color: "blue")[As of `3.3.4` functions referencing
511+
each other works with *diff*]
501512

502513
=== Examples
503514

src/configuration/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn load_color(string: String) -> Color {
131131

132132
pub fn replace_variable(str: String) -> String {
133133
str.replace("%author%", "Charlotte Thomas")
134-
.replace("%version%", "v3.3.3")
134+
.replace("%version%", "v3.3.4")
135135
.to_string()
136136
}
137137

src/interpreting/stdlib.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,26 @@ pub fn exec(
4040
"ceil" => ceil(&lst, &ram),
4141
"floor" => floor(&lst, &ram),
4242
"round" => round(&lst, &ram),
43-
"norm" => norm(&lst, &ram, functions),
43+
"norm" => norm(&lst, &ram, &functions),
4444
"transpose_vector" => transpose_vectors(&lst, &ram),
4545
"transpose" => transpose_matrices(&lst, &ram),
4646
"det" => det_matrix(&lst, &ram),
4747
"invert" => inverse_matrix(&lst, &ram),
48-
"plot" => plot_fn(&lst, &ram, functions, false),
49-
"termplot" => plot_fn(&lst, &ram, functions, true),
50-
"diff" => diff(&lst, &ram, functions),
48+
"plot" => plot_fn(&lst, &ram, &functions, false),
49+
"termplot" => plot_fn(&lst, &ram, &functions, true),
50+
"diff" => diff(&lst, &ram, &functions),
5151
s => {
5252
let mut sram: HashMap<String, Parameters> = HashMap::new();
5353
sram.insert("pi".to_string(), Float(PI));
5454
sram.insert("e".to_string(), Float(E));
5555
match functions.cloned() {
56-
None => Identifier("This function is unknown".to_string()),
56+
None => Identifier("@This function is unknown".to_string()),
5757
Some(mut f) => {
58-
let fs = f.get_mut(s);
59-
let (vec, ast): (&mut Vec<Ast>, &mut Ast) = match fs {
58+
let (vec, ast): (Vec<Ast>, Ast) = match f.get(s) {
6059
None => {
61-
return Identifier("This function is unknown".to_string());
60+
return Identifier("@This function is unknown".to_string());
6261
}
63-
Some((a, b)) => (a, b),
62+
Some((a, b)) => (a.clone(), b.clone()),
6463
};
6564

6665
let mut names = Vec::new();
@@ -88,7 +87,7 @@ pub fn exec(
8887
.for_each(|(name, param)| {
8988
sram.insert(name.to_string(), param);
9089
});
91-
interpret(ast, &mut sram, &mut HashMap::new())
90+
interpret(&ast, &mut sram, &mut f)
9291
}
9392
}
9493
}
@@ -1299,7 +1298,7 @@ pub fn round(p: &Vec<Parameters>, ram: &Option<&mut HashMap<String, Parameters>>
12991298
pub fn norm(
13001299
p: &Vec<Parameters>,
13011300
ram: &Option<&mut HashMap<String, Parameters>>,
1302-
function: Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
1301+
function: &Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
13031302
) -> Parameters {
13041303
if p.len() < 1 {
13051304
return Null;
@@ -1556,7 +1555,7 @@ pub fn inverse_matrix(
15561555
pub fn diff(
15571556
p: &Vec<Parameters>,
15581557
ram: &Option<&mut HashMap<String, Parameters>>,
1559-
function: Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
1558+
function: &Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
15601559
) -> Parameters {
15611560
let color = match load() {
15621561
Ok(cfg) => load_config(cfg).general_color,
@@ -1645,7 +1644,7 @@ pub fn diff(
16451644
p.to_string(),
16461645
vec![Identifier("x".to_string())],
16471646
Some(&mut c),
1648-
function,
1647+
Some(&mut s),
16491648
);
16501649
match param {
16511650
Identifier(_) => Int(1),
@@ -1654,20 +1653,21 @@ pub fn diff(
16541653
y - 1,
16551654
z,
16561655
),
1656+
16571657
Plus(x, y) => other_add(
1658-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1659-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1658+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
1659+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
16601660
Some(&c),
16611661
),
16621662
Mul(x, y) => other_add(
16631663
mult(
16641664
*x.clone(),
1665-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1665+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
16661666
Some(&c),
16671667
),
16681668
mult(
16691669
*y.clone(),
1670-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1670+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
16711671
Some(&c),
16721672
),
16731673
Some(&c),
@@ -1676,24 +1676,24 @@ pub fn diff(
16761676
Box::from(other_add(
16771677
mult(
16781678
*x.clone(),
1679-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1679+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
16801680
Some(&c),
16811681
),
16821682
mult(
16831683
mult(Int(-1), *y.clone(), Some(&c)),
1684-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1684+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
16851685
Some(&c),
16861686
),
16871687
Some(&c),
16881688
)),
16891689
Box::from(mult(*y.clone(), *y.clone(), Some(&c))),
16901690
),
16911691
Call(name, pst) => {
1692-
let prefix = diff(&vec![*pst.clone()], &Some(&mut c), Some(&mut s));
1692+
let prefix = diff(&vec![*pst.clone()], &Some(&mut c), &Some(&mut s));
16931693
let call = diff(
16941694
&vec![Identifier(name), *pst.clone()],
16951695
&Some(&mut c),
1696-
Some(&mut s),
1696+
&Some(&mut s),
16971697
);
16981698
mult(prefix, call, Some(&c))
16991699
}
@@ -1707,19 +1707,19 @@ pub fn diff(
17071707
z.clone(),
17081708
),
17091709
Plus(x, y) => other_add(
1710-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1711-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1710+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
1711+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
17121712
Some(&c),
17131713
),
17141714
Mul(x, y) => other_add(
17151715
mult(
17161716
*x.clone(),
1717-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1717+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
17181718
Some(&c),
17191719
),
17201720
mult(
17211721
*y.clone(),
1722-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1722+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
17231723
Some(&c),
17241724
),
17251725
Some(&c),
@@ -1728,12 +1728,12 @@ pub fn diff(
17281728
Box::from(other_add(
17291729
mult(
17301730
*x.clone(),
1731-
diff(&vec![*y.clone()], &Some(&mut c), Some(&mut s)),
1731+
diff(&vec![*y.clone()], &Some(&mut c), &Some(&mut s)),
17321732
Some(&c),
17331733
),
17341734
mult(
17351735
Mul(Box::from(Int(-1)), y.clone()),
1736-
diff(&vec![*x.clone()], &Some(&mut c), Some(&mut s)),
1736+
diff(&vec![*x.clone()], &Some(&mut c), &Some(&mut s)),
17371737
Some(&c),
17381738
),
17391739
Some(&c),
@@ -1742,11 +1742,11 @@ pub fn diff(
17421742
),
17431743

17441744
Call(name, pst) => {
1745-
let prefix = diff(&vec![*pst.clone()], &Some(&mut c), Some(&mut s));
1745+
let prefix = diff(&vec![*pst.clone()], &Some(&mut c), &Some(&mut s));
17461746
let call = diff(
17471747
&vec![Identifier(name.to_string()), *pst.clone()],
17481748
&Some(&mut c),
1749-
Some(&mut s),
1749+
&Some(&mut s),
17501750
);
17511751
mult(prefix, call, Some(&c))
17521752
}
@@ -1757,7 +1757,7 @@ pub fn diff(
17571757
pub fn plot_fn(
17581758
p: &Vec<Parameters>,
17591759
ram: &Option<&mut HashMap<String, Parameters>>,
1760-
functions: Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
1760+
functions: &Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
17611761
terminal: bool,
17621762
) -> Parameters {
17631763
let color = match load() {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn handle_config(line: &str, config: Config) -> (String, Option<Config>) {
263263
fn main() {
264264
let mut args: Args = env::args();
265265

266-
let version: String = "v3.3.3".to_string();
266+
let version: String = "v3.3.4".to_string();
267267
if args.len() > 1 || !atty::is(Stream::Stdin) {
268268
let mut a = vec![];
269269

src/parsing/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Parameters {
156156
if s.starts_with("@") {
157157
match s.strip_prefix("@") {
158158
None => format!(""),
159-
Some(c) => format!("{c}"),
159+
Some(c) => format!("Error: {}", Color::Red.paint(c)),
160160
}
161161
} else {
162162
if ram == None {

0 commit comments

Comments
 (0)