Minor changes

This commit is contained in:
2023-04-01 19:05:40 -07:00
parent a06b76705a
commit d3d13a64ff
3 changed files with 16 additions and 7 deletions

View File

@ -102,11 +102,17 @@ impl Quantity {
}
}
pub fn new_float_from_string(s: &str) -> Quantity {
pub fn new_float_from_string(s: &str) -> Option<Quantity> {
let v = Float::parse(s);
return Quantity::Float {
v: Float::with_val(FLOAT_PRECISION, v.unwrap())
}
let v = match v {
Ok(x) => x,
Err(_) => return None
};
return Some(Quantity::Float {
v: Float::with_val(FLOAT_PRECISION, v)
})
}
@ -189,6 +195,7 @@ impl Quantity {
}
quick_quant_fn!(fract);
quick_quant_fn!(exp);
quick_quant_fn!(abs);
quick_quant_fn!(floor);

View File

@ -86,6 +86,8 @@ impl RationalQ {
}
pub fn exp(&self) -> Quantity {float!(self.to_float().exp())}
pub fn abs(&self) -> Quantity {rational!(self.val.clone().abs())}
pub fn floor(&self) -> Quantity {rational!(self.val.clone().floor())}
pub fn ceil(&self) -> Quantity {rational!(self.val.clone().ceil())}