diff --git a/Cargo.lock b/Cargo.lock index 55aec00..825a11a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "daisy" -version = "0.2.2" +version = "0.2.3" dependencies = [ "cfg-if", "rug", diff --git a/Cargo.toml b/Cargo.toml index e66fcda..1d9a4df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daisy" -version = "0.2.2" +version = "0.2.3" edition = "2021" [profile.release] diff --git a/TODO.md b/TODO.md index df997ce..7685840 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ - Prettyprint mi/h, mi/g - Better constant definitions - - No times when number * unit - Fix unit conversion (km/s * mile) ## Pre-release diff --git a/src/parser/token/operator.rs b/src/parser/token/operator.rs index c327e00..bfbcbe3 100644 --- a/src/parser/token/operator.rs +++ b/src/parser/token/operator.rs @@ -264,7 +264,7 @@ impl Operator { let a = &args[0]; let b; let sub; - if let Token::Operator(o,ar) = &args[1] { + if let Token::Operator(o, ar) = &args[1] { if let Operator::Negative = o { sub = true; b = &ar[0]; @@ -290,18 +290,38 @@ impl Operator { let a = &args[0]; let b; let div; - if let Token::Operator(o,ar) = &args[1] { + if let Token::Operator(o, ar) = &args[1] { if let Operator::Flip = o { div = true; b = &ar[0]; } else { div = false; b = &args[1]; } } else { div = false; b = &args[1]; } + // Division symbol case if div { return format!("{} ÷ {}", self.add_parens_to_arg_strict(a), self.add_parens_to_arg_strict(b) ); + } + + + // Omit times sign when we have a number + // multiplied by a unit (like 10 m) + // Times sign should stay in all other cases. + let no_times = { + if let Token::Quantity(p) = a { + if let Token::Quantity(q) = b { + p.unitless() && !q.unitless() + } else {false} + } else {false} + }; + + if no_times { + return format!("{} {}", + self.add_parens_to_arg_strict(a), + self.add_parens_to_arg_strict(b) + ); } else { return format!("{} × {}", self.add_parens_to_arg_strict(a),