mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-27 21:21:42 +02:00
Added permutation functions (for nPr and nCr), closes #52
This commit is contained in:
parent
de6e5106e9
commit
dae1e9f290
@ -107,6 +107,10 @@ lazy_static! {
|
|||||||
m.insert("lcm", (BinaryFuncInfo(lcm, Other), ""));
|
m.insert("lcm", (BinaryFuncInfo(lcm, Other), ""));
|
||||||
m.insert("log", (BinaryFuncInfo(logx, Other), ""));
|
m.insert("log", (BinaryFuncInfo(logx, Other), ""));
|
||||||
m.insert("root", (BinaryFuncInfo(nth_root, Other), ""));
|
m.insert("root", (BinaryFuncInfo(nth_root, Other), ""));
|
||||||
|
m.insert("nCr", (BinaryFuncInfo(ncr, Other), ""));
|
||||||
|
m.insert("comb", (BinaryFuncInfo(ncr, Other), ""));
|
||||||
|
m.insert("nPr", (BinaryFuncInfo(npr, Other), ""));
|
||||||
|
m.insert("perm", (BinaryFuncInfo(npr, Other), ""));
|
||||||
m
|
m
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -222,6 +226,7 @@ fn from_angle_unit(context: &mut interpreter::Context, x: KalkNum, angle_unit: &
|
|||||||
pub mod funcs {
|
pub mod funcs {
|
||||||
#[cfg(not(feature = "rug"))]
|
#[cfg(not(feature = "rug"))]
|
||||||
pub use super::regular::funcs::*;
|
pub use super::regular::funcs::*;
|
||||||
|
use super::special_funcs::factorial;
|
||||||
#[cfg(feature = "rug")]
|
#[cfg(feature = "rug")]
|
||||||
pub use super::with_rug::funcs::*;
|
pub use super::with_rug::funcs::*;
|
||||||
use crate::kalk_num::KalkNum;
|
use crate::kalk_num::KalkNum;
|
||||||
@ -715,6 +720,16 @@ pub mod funcs {
|
|||||||
KalkNum::new_with_imaginary(x.value.trunc(), &x.unit, x.imaginary_value.trunc())
|
KalkNum::new_with_imaginary(x.value.trunc(), &x.unit, x.imaginary_value.trunc())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ncr(x: KalkNum, y: KalkNum) -> KalkNum {
|
||||||
|
factorial(x.clone()).div_without_unit(
|
||||||
|
factorial(y.clone()).mul_without_unit(factorial(x.sub_without_unit(y))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn npr(x: KalkNum, y: KalkNum) -> KalkNum {
|
||||||
|
factorial(x.clone()).div_without_unit(factorial(x.sub_without_unit(y)))
|
||||||
|
}
|
||||||
|
|
||||||
fn multiply_with_i(z: KalkNum) -> KalkNum {
|
fn multiply_with_i(z: KalkNum) -> KalkNum {
|
||||||
// iz = i(a + bi) = -b + ai
|
// iz = i(a + bi) = -b + ai
|
||||||
KalkNum::new_with_imaginary(-z.imaginary_value, &z.unit, z.value)
|
KalkNum::new_with_imaginary(-z.imaginary_value, &z.unit, z.value)
|
||||||
|
@ -50,8 +50,8 @@ pub(crate) mod funcs {
|
|||||||
2f64.sqrt() * pi.sqrt() * t.powf(x - 0.5f64) * (-t).exp() * a
|
2f64.sqrt() * pi.sqrt() * t.powf(x - 0.5f64) * (-t).exp() * a
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bitcmp(x: KalkNum, y: KalkNum) -> KalkNum {
|
pub fn bitcmp(x: KalkNum) -> KalkNum {
|
||||||
KalkNum::from(!x.value.round() as i32)
|
KalkNum::from(!(x.value.round() as i32))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bitand(x: KalkNum, y: KalkNum) -> KalkNum {
|
pub fn bitand(x: KalkNum, y: KalkNum) -> KalkNum {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user