aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md45
-rw-r--r--qc.pngbin0 -> 6632 bytes
-rw-r--r--src/eval.rs7
-rw-r--r--src/op.rs2
-rw-r--r--src/parser.rs4
5 files changed, 58 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..718e608
--- /dev/null
+++ b/README.md
@@ -0,0 +1,45 @@
+# qc
+
+qc is a minimalist desktop calculator app written
+in blazingly fast™ Rust.
+
+![sqrt(2^64) = 4294967296](qc.png)
+
+## Syntax
+
+All of your favorite mathematical operators are supported:
+
+ - `+`: add
+ - `-`: subtract
+ - `*`: multiply
+ - `/`: divide
+ - `//`: computes integer division between two numbers. If the arguments
+ are not both integers, equivalent to `trunc(x/y)`
+ - `%`: modulo
+ - `^`: exponentiation
+
+Adjacent terms are multiplied:
+ - `2pi`
+ - `2log10(100)`
+
+### Functions
+
+There are also a number of numerical functions:
+ - `sqrt`
+ - `log` (or `ln`, `log2` and `log10` also available)
+ - `sin`
+ - `cos`
+ - `tan`
+ - `asin` (or `arcsin`)
+ - `acos` (or `acos`)
+ - `atan` (or `arctan`)
+ - `floor`
+ - `ceil` (or `ceiling`)
+ - `round`
+ - `trunc` (or `truncate`)
+ - `abs`
+
+Parentheses are optional when calling a function:
+
+ - `cos pi` (equivalent to `cos(pi)`)
+ - `cos 2pi` (equivalent to `(cos(2))*pi`)
diff --git a/qc.png b/qc.png
new file mode 100644
index 0000000..c6d48dc
--- /dev/null
+++ b/qc.png
Binary files differ
diff --git a/src/eval.rs b/src/eval.rs
index a72f271..e40743b 100644
--- a/src/eval.rs
+++ b/src/eval.rs
@@ -179,6 +179,13 @@ impl Num {
}
}
+ pub fn trunc(self) -> Num {
+ match self {
+ Int(i) => Int(i),
+ Float(f) => Int(f as i128),
+ }
+ }
+
pub fn abs(self) -> Num {
match self {
Int(i) => Int(i.abs()),
diff --git a/src/op.rs b/src/op.rs
index 6a2d00f..b2f2a3f 100644
--- a/src/op.rs
+++ b/src/op.rs
@@ -16,6 +16,7 @@ pub enum UnOp {
Floor,
Ceil,
Round,
+ Trunc,
Abs,
}
@@ -36,6 +37,7 @@ impl UnOp {
UnOp::Floor => x.floor(),
UnOp::Ceil => x.ceil(),
UnOp::Round => x.round(),
+ UnOp::Trunc => x.trunc(),
UnOp::Abs => x.abs(),
}
}
diff --git a/src/parser.rs b/src/parser.rs
index a31b4f9..1e271a4 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -130,6 +130,10 @@ impl<'a> Parser<'a> {
self.stack.push(Pending::Un(UnOp::Round));
return true;
}
+ if self.symbol("trunc") {
+ self.stack.push(Pending::Un(UnOp::Trunc));
+ return true;
+ }
if self.symbol("abs") {
self.stack.push(Pending::Un(UnOp::Abs));
return true;