Minor fixes

pull/2/head
Mark 2023-04-01 18:27:47 -07:00
parent cb227d9539
commit f07ba9ed38
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 11 additions and 7 deletions

View File

@ -116,10 +116,10 @@ impl Quantity {
} }
} }
pub fn new_rational_from_string(s: &str) -> Quantity { pub fn new_rational_from_string(s: &str) -> Option<Quantity> {
return Quantity::Rational { let r = RationalQ::from_string(s);
v: RationalQ::from_string(s) if r.is_none() { return None; }
} return Some(Quantity::Rational { v: r.unwrap() });
} }
pub fn new_rational_from_f64(f: f64) -> pub fn new_rational_from_f64(f: f64) ->

View File

@ -63,9 +63,13 @@ impl RationalQ {
return Some(RationalQ{ val: v.unwrap() }); return Some(RationalQ{ val: v.unwrap() });
} }
pub fn from_string(s: &str) -> RationalQ { pub fn from_string(s: &str) -> Option<RationalQ> {
let v = Rational::from_str_radix(s, 10); let v = Rational::from_str_radix(s, 10);
return RationalQ{ val: v.unwrap() }; let v = match v {
Ok(x) => x,
Err(_) => return None
};
return Some(RationalQ{ val: v });
} }
pub fn to_float(&self) -> Float { pub fn to_float(&self) -> Float {

View File

@ -572,7 +572,7 @@ impl Operator{
if let Token::Number(v) = args { if let Token::Number(v) = args {
if !v.fract().is_zero() { return Err(()); } if !v.fract().is_zero() { return Err(()); }
if v >= Quantity::new_rational(100, 1) { return Err(()); } if v > Quantity::new_rational(50_000, 1) { return Err(()); }
let mut prod = Quantity::new_rational(1, 1); let mut prod = Quantity::new_rational(1, 1);
let mut u = v.clone(); let mut u = v.clone();