Minor changes

pull/2/head
Mark 2023-04-01 19:05:40 -07:00
parent a06b76705a
commit d3d13a64ff
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 16 additions and 7 deletions

View File

@ -85,9 +85,9 @@ impl PreToken {
return Ok(match &s[..] { return Ok(match &s[..] {
// Mathematical constants // Mathematical constants
// 100 digits of each. // 100 digits of each.
"π"|"pi" => { Token::Constant(Quantity::new_float_from_string("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067"), String::from("π")) }, "π"|"pi" => { Token::Constant(Quantity::new_float_from_string("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067").unwrap(), String::from("π")) },
"e" => { Token::Constant(Quantity::new_float_from_string("2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427"), String::from("e")) }, "e" => { Token::Constant(Quantity::new_float_from_string("2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427").unwrap(), String::from("e")) },
"phi"|"φ" => { Token::Constant(Quantity::new_float_from_string("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137"), String::from("φ")) }, "phi"|"φ" => { Token::Constant(Quantity::new_float_from_string("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137").unwrap(), String::from("φ")) },
_ => { return Err((l, ParserError::Undefined(s))); } _ => { return Err((l, ParserError::Undefined(s))); }
}); });

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); 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!(fract);
quick_quant_fn!(exp);
quick_quant_fn!(abs); quick_quant_fn!(abs);
quick_quant_fn!(floor); 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 abs(&self) -> Quantity {rational!(self.val.clone().abs())}
pub fn floor(&self) -> Quantity {rational!(self.val.clone().floor())} pub fn floor(&self) -> Quantity {rational!(self.val.clone().floor())}
pub fn ceil(&self) -> Quantity {rational!(self.val.clone().ceil())} pub fn ceil(&self) -> Quantity {rational!(self.val.clone().ceil())}