mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-03-11 03:28:12 +01:00
Added 'sgn' function
This commit is contained in:
parent
2bda63b058
commit
11869d1fef
@ -77,6 +77,7 @@ lazy_static! {
|
||||
m.insert("log", (UnaryFuncInfo(log, Other), ""));
|
||||
m.insert("Re", (UnaryFuncInfo(re, Other), ""));
|
||||
m.insert("round", (UnaryFuncInfo(round, Other), ""));
|
||||
m.insert("sgn", (UnaryFuncInfo(sgn, Other), ""));
|
||||
m.insert("sqrt", (UnaryFuncInfo(sqrt, Other), ""));
|
||||
m.insert("√", (UnaryFuncInfo(sqrt, Other), ""));
|
||||
m.insert("transpose", (UnaryFuncInfo(transpose, Other), ""));
|
||||
@ -783,6 +784,16 @@ pub mod funcs {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn sgn(x: KalkValue) -> KalkValue {
|
||||
if x.has_imaginary() {
|
||||
x.clone().div_without_unit(&abs(x))
|
||||
} else {
|
||||
let (real, _, unit) = as_number_or_return!(x);
|
||||
|
||||
KalkValue::Number(real.signum(), float!(0), unit)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sqrt(x: KalkValue) -> KalkValue {
|
||||
let (real, imaginary, unit) = as_number_or_return!(x.clone());
|
||||
if x.has_imaginary() {
|
||||
|
Loading…
Reference in New Issue
Block a user