Added 'length' function and added 'permutations' as an alias to 'perms' function

This commit is contained in:
bakk 2022-01-23 00:32:58 +01:00 committed by PaddiM8
parent d4a9dad153
commit 707114006b

View File

@ -74,6 +74,7 @@ lazy_static! {
m.insert("iverson", (UnaryFuncInfo(iverson, Other), ""));
m.insert("Im", (UnaryFuncInfo(im, Other), ""));
m.insert("ln", (UnaryFuncInfo(ln, Other), ""));
m.insert("length", (UnaryFuncInfo(length, Other), ""));
m.insert("log", (UnaryFuncInfo(log, Other), ""));
m.insert("Re", (UnaryFuncInfo(re, Other), ""));
m.insert("round", (UnaryFuncInfo(round, Other), ""));
@ -109,6 +110,7 @@ lazy_static! {
m.insert("max", VectorFuncInfo(max, Other));
m.insert("min", VectorFuncInfo(min, Other));
m.insert("perms", VectorFuncInfo(perms, Other));
m.insert("permutations", VectorFuncInfo(perms, Other));
m
};
}
@ -720,6 +722,14 @@ pub mod funcs {
}
}
pub fn length(x: KalkValue) -> KalkValue {
match x {
KalkValue::Vector(values) => KalkValue::from(values.len() as f64),
KalkValue::Matrix(rows) => KalkValue::from(rows.len() as f64),
_ => KalkValue::from(0f64),
}
}
pub fn max(x: KalkValue) -> KalkValue {
let values = as_vector_or_return!(x);
let mut max = &values[0];