diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-31 11:23:32 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-31 11:23:32 -0700 |
| commit | 46fcf485140bfd3f6d8576d3996770615aef29f0 (patch) | |
| tree | b2ae21808e705d38ec4fd8ea1322b6c82e258d15 | |
| parent | 55dfd5ea5ad834fcf636c96662252d450a2d736c (diff) | |
| download | qc-46fcf485140bfd3f6d8576d3996770615aef29f0.tar.zst | |
Add a README
| -rw-r--r-- | README.md | 45 | ||||
| -rw-r--r-- | qc.png | bin | 0 -> 6632 bytes | |||
| -rw-r--r-- | src/eval.rs | 7 | ||||
| -rw-r--r-- | src/op.rs | 2 | ||||
| -rw-r--r-- | src/parser.rs | 4 |
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. + + + +## 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`) Binary files differdiff --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()), @@ -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; |
