Skip to content

Commit

Permalink
Add kgf and kilopond units
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Nov 1, 2024
1 parent 9559d9b commit aea224b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/num/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,13 @@ impl Unit {
decimal_separator: DecimalSeparatorStyle,
int: &I,
) -> FResult<String> {
let from_base_units: Vec<_> = hash
let mut from_base_units: Vec<_> = hash
.into_iter()
.map(|(base_unit, exponent)| {
UnitExponent::new(NamedUnit::new_from_base(base_unit), exponent)
})
.collect();
from_base_units.sort_by(|a, b| a.unit.singular_name.cmp(&b.unit.singular_name));
Ok(Self {
components: from_base_units,
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/units/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ const CGS_UNITS: &[UnitTuple] = &[
("G", "", "gauss", ""),
("Mx", "", "maxwell", ""),
("ph", "", "phot", ""),
("gf", "", "s@g force", ""),
("pond", "", "l@gf", ""),
];

const IMPERIAL_UNITS: &[UnitTuple] = &[
Expand Down
8 changes: 8 additions & 0 deletions core/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6078,3 +6078,11 @@ fn european_formatting() {
"approx. 0,9320390859"
);
}

#[test]
fn kilopond() {
test_eval("kilopond to N", "9.80665 N");
test_eval("megapond to N", "9806.65 N");
test_eval("gf to N", "0.00980665 N");
expect_error("GF to N", Some("cannot convert from GF to N: units 'ampere^2 second^4 kilogram^-1 meter^-2' and 'kilogram meter / second^2' are incompatible"));
}

0 comments on commit aea224b

Please sign in to comment.