Skip to content

Commit

Permalink
Fix default unit ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Dec 27, 2023
1 parent d85324b commit 9a402ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/src/units/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,19 +835,19 @@ pub(crate) fn query_unit(
}

const DEFAULT_UNITS: &[(&str, &str)] = &[
("second^-1", "hertz"),
("kilogram^1 meter^1 second^-2", "newton"),
("kilogram^1 meter^-1 second^-2", "pascal"),
("kilogram^1 meter^2 second^-2", "joule"),
("kilogram^1 meter^2 second^-3", "watt"),
("hertz", "second^-1"),
("newton", "kilogram^1 meter^1 second^-2"),
("pascal", "kilogram^1 meter^-1 second^-2"),
("joule", "kilogram^1 meter^2 second^-2"),
("watt", "kilogram^1 meter^2 second^-3"),
("ohm", "ampere^-2 kilogram meter^2 second^-3"),
("volt", "ampere^-1 kilogram meter^2 second^-3"),
("liter", "meter^3"),
];

pub(crate) fn lookup_default_unit(base_units: &str) -> Option<&str> {
if let Some((_, unit)) = DEFAULT_UNITS.iter().find(|(base, _)| *base == base_units) {
return Some(unit);
if let Some((unit_name, _)) = DEFAULT_UNITS.iter().find(|(_, base)| *base == base_units) {
return Some(unit_name);
}
if let Some((singular, _, _, _)) = BASE_UNITS
.iter()
Expand Down

0 comments on commit 9a402ce

Please sign in to comment.