mirror of
https://github.com/rm-dr/daisy
synced 2025-07-05 01:59:30 -07:00
Compound unit foundation
This commit is contained in:
@ -93,31 +93,30 @@ impl PreToken {
|
||||
let c = match &s[..] {
|
||||
// Mathematical constants
|
||||
// 100 digits of each.
|
||||
"π"|"pi" => { Some(Token::Constant(Quantity::new_float_from_string(
|
||||
"π"|"pi" => { Some((Quantity::new_float_from_string(
|
||||
"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067"
|
||||
).unwrap(), String::from("π")))},
|
||||
|
||||
"e" => { Some(Token::Constant(Quantity::new_float_from_string(
|
||||
"e" => { Some((Quantity::new_float_from_string(
|
||||
"2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427"
|
||||
).unwrap(), String::from("e"))) },
|
||||
|
||||
"phi"|"φ" => { Some(Token::Constant(Quantity::new_float_from_string(
|
||||
"phi"|"φ" => { Some((Quantity::new_float_from_string(
|
||||
"1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137"
|
||||
).unwrap(), String::from("φ"))) },
|
||||
|
||||
_ => { None }
|
||||
};
|
||||
|
||||
if c.is_some() { return Ok(c.unwrap()); }
|
||||
|
||||
let c = Unit::from_string(&s);
|
||||
|
||||
if c.is_some() {
|
||||
let mut q = Quantity::new_rational(1f64).unwrap();
|
||||
q.set_unit(c.unwrap());
|
||||
return Ok(Token::Number(q));
|
||||
let (a, b) = c.unwrap();
|
||||
return Ok(Token::Constant(a, b));
|
||||
}
|
||||
|
||||
let c = Quantity::from_unit_string(&s);
|
||||
|
||||
if c.is_some() { return Ok(Token::Number(c.unwrap())); }
|
||||
|
||||
return Err((l, ParserError::Undefined(s)));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user