From d24d4af969fb1b2baeca9d6bc4149387e5b5eba9 Mon Sep 17 00:00:00 2001 From: Ethan Wu Date: Sun, 11 Oct 2020 21:07:50 -0700 Subject: [PATCH] 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 --- src/lexer.rs | 2 +- src/units.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index d7d1af5..f519c3b 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -163,7 +163,7 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> "day" | "days" => tokens.push(Token::Unit(Day)), "wk" | "wks" | "week" | "weeks" => tokens.push(Token::Unit(Week)), "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)), "decade" | "decades" => tokens.push(Token::Unit(Decade)), "century" | "centuries" => tokens.push(Token::Unit(Century)), diff --git a/src/units.rs b/src/units.rs index fb16ae8..2a5f718 100644 --- a/src/units.rs +++ b/src/units.rs @@ -422,7 +422,7 @@ pub fn divide(left: Number, right: Number) -> Result { } else if lcat == rcat { // 1 km / 1 km 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) { // 1 km2 / 1 km, 1 km3 / 1 km2 let result = (left.value * left.unit.weight()) / (right.value * right.unit.weight());