···468468/// If one of two provided [`Number`]s has a larger [`Unit`] than the other, convert
469469/// the large one to the unit of the small one.
470470pub fn convert_to_lowest(left: Number, right: Number) -> Result<(Number, Number), String> {
471471- todo!();
472472- // if left.unit.weight() == right.unit.weight() {
473473- // Ok((left, right))
474474- // } else if left.unit.weight() > right.unit.weight() {
475475- // let left_converted = convert(left, right.unit)?;
476476- // Ok((left_converted, right))
477477- // } else {
478478- // let right_converted = convert(right, left.unit)?;
479479- // Ok((left, right_converted))
480480- // }
471471+ assert!(left.primitive_unit() == right.primitive_unit());
472472+ if combined_weight(&left.unit) == combined_weight(&right.unit) {
473473+ Ok((left, right))
474474+ } else if combined_weight(&left.unit) > combined_weight(&right.unit) {
475475+ let left_converted = convert(left, right.unit.clone())?;
476476+ Ok((left_converted, right))
477477+ } else {
478478+ let right_converted = convert(right, left.unit.clone())?;
479479+ Ok((left, right_converted))
480480+ }
481481}
482482483483/// Return the sum of two [`Number`]s