Fix bugs caused by typos

- Fix spelling of *quarter* in lexer and assign `Unit::Quarter` correctly
- Use division instead of multiplication when dividing a number by another
  number of the same unit
This commit is contained in:
Ethan Wu 2020-10-11 21:07:50 -07:00
parent 18625d9205
commit d24d4af969
2 changed files with 2 additions and 2 deletions

View File

@ -163,7 +163,7 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
"day" | "days" => tokens.push(Token::Unit(Day)), "day" | "days" => tokens.push(Token::Unit(Day)),
"wk" | "wks" | "week" | "weeks" => tokens.push(Token::Unit(Week)), "wk" | "wks" | "week" | "weeks" => tokens.push(Token::Unit(Week)),
"mo" | "mos" | "month" | "months" => tokens.push(Token::Unit(Month)), "mo" | "mos" | "month" | "months" => tokens.push(Token::Unit(Month)),
"q" | "quater" | "quaters" => tokens.push(Token::Unit(Month)), "q" | "quarter" | "quarters" => tokens.push(Token::Unit(Quarter)),
"yr" | "yrs" | "year" | "years" => tokens.push(Token::Unit(Year)), "yr" | "yrs" | "year" | "years" => tokens.push(Token::Unit(Year)),
"decade" | "decades" => tokens.push(Token::Unit(Decade)), "decade" | "decades" => tokens.push(Token::Unit(Decade)),
"century" | "centuries" => tokens.push(Token::Unit(Century)), "century" | "centuries" => tokens.push(Token::Unit(Century)),

View File

@ -422,7 +422,7 @@ pub fn divide(left: Number, right: Number) -> Result<Number, String> {
} else if lcat == rcat { } else if lcat == rcat {
// 1 km / 1 km // 1 km / 1 km
let (left, right) = convert_to_lowest(left, right)?; let (left, right) = convert_to_lowest(left, right)?;
Ok(Number::new(left.value * right.value, NoUnit)) Ok(Number::new(left.value / right.value, NoUnit))
} else if (lcat == Area && rcat == Length) || (lcat == Volume && rcat == Area) { } else if (lcat == Area && rcat == Length) || (lcat == Volume && rcat == Area) {
// 1 km2 / 1 km, 1 km3 / 1 km2 // 1 km2 / 1 km, 1 km3 / 1 km2
let result = (left.value * left.unit.weight()) / (right.value * right.unit.weight()); let result = (left.value * left.unit.weight()) / (right.value * right.unit.weight());