Fixed unit multiplication prettyprint

pull/2/head
Mark 2023-06-11 15:16:00 -07:00
parent b886927334
commit e816cea236
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 24 additions and 5 deletions

2
Cargo.lock generated
View File

@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "daisy"
version = "0.2.2"
version = "0.2.3"
dependencies = [
"cfg-if",
"rug",

View File

@ -1,6 +1,6 @@
[package]
name = "daisy"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
[profile.release]

View File

@ -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

View File

@ -297,11 +297,31 @@ impl Operator {
} 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),