feat: add abs function
This commit is contained in:
parent
b7ce85c3f4
commit
4eb6f55f9a
4 changed files with 12 additions and 0 deletions
|
|
@ -153,6 +153,8 @@ impl Function {
|
|||
Self::ArcTangent => Float::atan_mut(n),
|
||||
Self::Secant => Float::sec_mut(n),
|
||||
Self::CoSecant => Float::csc_mut(n),
|
||||
|
||||
Self::Abs => Float::abs_mut(n),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,4 +86,6 @@ pub enum Function {
|
|||
ArcTangent,
|
||||
Secant,
|
||||
CoSecant,
|
||||
|
||||
Abs,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,9 @@ impl FromStr for Function {
|
|||
"atan" | "arctan" => Ok(Self::ArcTangent),
|
||||
"sec" => Ok(Self::Secant),
|
||||
"csc" => Ok(Self::CoSecant),
|
||||
|
||||
"abs" => Ok(Self::Abs),
|
||||
|
||||
_ => Err(s.to_owned()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,3 +63,8 @@ fn operator_after_parenthesis() {
|
|||
assert_eq!(eval("(0.2)20^2"), 80.);
|
||||
assert_eq!(eval("(0.2)20^2/2 - (0.2)10^2/2"), 30.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abs() {
|
||||
assert_eq!(eval("abs(-1)"), 1.);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue