Compare commits
No commits in common. "13d381d15fd4ca7934a3c166fe08f2778f7cf269" and "f149e57f07d6b81c7149c2f97d523d5e61ba4fa2" have entirely different histories.
13d381d15f
...
f149e57f07
4 changed files with 28 additions and 19 deletions
|
@ -6,5 +6,5 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
evalexpr = "11.0.0"
|
evalexpr = "7.2.0"
|
||||||
termion = "1.5.6"
|
termion = "1.5.6"
|
||||||
|
|
28
README.md
28
README.md
|
@ -7,7 +7,33 @@ Features expression evaluation, variable assignment, an interactive mode, pretty
|
||||||
output, and a variety of preset constants and functions focused on pure mathematics,
|
output, and a variety of preset constants and functions focused on pure mathematics,
|
||||||
data science, and computer science.
|
data science, and computer science.
|
||||||
|
|
||||||
More information is available on the [project wiki](https://git.vwolfe.io/valerie/qm/wiki).
|
## Constants
|
||||||
|
|
||||||
|
| Name | Tokens | Type | Value |
|
||||||
|
| -------------- | ---------- | ----- | ------------------- |
|
||||||
|
| Euler's Number | `e` | `f64` | `2.718281828459045` |
|
||||||
|
| Golden Ratio | `phi`, `ϕ` | `f64` | `1.618033988749895` |
|
||||||
|
| Pi | `pi`, `π` | `f64` | `3.141592653589793` |
|
||||||
|
| Root Two | `√2` | `f64` | `1.414213562373095` |
|
||||||
|
|
||||||
|
|
||||||
|
## Built-in functions
|
||||||
|
|
||||||
|
### Mathematics
|
||||||
|
|
||||||
|
- `fix`: fix a float to *n* digits.
|
||||||
|
- `log`: logarithm. Defaults to natural logarithm (ln).
|
||||||
|
- `sqrt`/`√`: square root.
|
||||||
|
|
||||||
|
### Data Science
|
||||||
|
|
||||||
|
- `avg`: average an arbitrary set of numbers.
|
||||||
|
|
||||||
|
### Computer Science
|
||||||
|
|
||||||
|
- `bin`: convert an integer to a binary string or vice versa.
|
||||||
|
- `hex`: convert an integer to a hexadecimal string or vice versa.
|
||||||
|
- `oct`: convert an integer to an octal string or vice versa.
|
||||||
|
|
||||||
## Libraries
|
## Libraries
|
||||||
|
|
||||||
|
|
|
@ -7,22 +7,6 @@ use evalexpr::{
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
// Mathematics
|
// Mathematics
|
||||||
pub fn fix(arg: &Value) -> Result<Value, EvalexprError> {
|
|
||||||
let args = arg.as_tuple()?;
|
|
||||||
|
|
||||||
let count = args.len();
|
|
||||||
if count != 2 {
|
|
||||||
return Err(EvalexprError::WrongFunctionArgumentAmount { expected: 2, actual: count });
|
|
||||||
}
|
|
||||||
|
|
||||||
let float = args[0].as_float()?;
|
|
||||||
let figures = args[1].as_int()?;
|
|
||||||
|
|
||||||
let operand: f64 = i64::pow(10, figures as u32) as f64;
|
|
||||||
let output = f64::round(float * operand) / operand;
|
|
||||||
return Ok(output.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn logarithm(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn logarithm(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
let arguments: Vec<Value>;
|
let arguments: Vec<Value>;
|
||||||
let count: usize;
|
let count: usize;
|
||||||
|
|
|
@ -36,7 +36,6 @@ fn main() {
|
||||||
"√2" => global::ROOT_TWO,
|
"√2" => global::ROOT_TWO,
|
||||||
|
|
||||||
// math functions
|
// math functions
|
||||||
"fix" => Function::new(|arg| helper::fix(arg)),
|
|
||||||
"log" => Function::new(|arg| helper::logarithm(arg)),
|
"log" => Function::new(|arg| helper::logarithm(arg)),
|
||||||
"sqrt" => Function::new(|arg| helper::square_root(arg)),
|
"sqrt" => Function::new(|arg| helper::square_root(arg)),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue