mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Prevent weird decompositions like Pa m -> A tesla
This commit is contained in:
parent
685e5149d1
commit
0041d12b1e
2 changed files with 10 additions and 2 deletions
|
@ -25,7 +25,15 @@ impl cmp::Ord for Factors {
|
|||
|
||||
pub fn fast_decompose(value: &Number, aliases: &BTreeMap<Unit, String>) -> Unit {
|
||||
let mut best = None;
|
||||
for (unit, name) in aliases.iter() {
|
||||
'outer: for (unit, name) in aliases.iter() {
|
||||
// make sure we aren't doing something weird like introducing new base units
|
||||
for (dim, pow) in unit {
|
||||
let vpow = value.1.get(dim).cloned().unwrap_or(0);
|
||||
let snum = (vpow - pow).signum();
|
||||
if snum != 0 && snum != vpow.signum() {
|
||||
continue 'outer
|
||||
}
|
||||
}
|
||||
let num = Number(Mpq::one(), unit.clone());
|
||||
for &i in [-1, 1, 2].into_iter() {
|
||||
let res = (value / &num.powi(i)).unwrap();
|
||||
|
|
|
@ -37,5 +37,5 @@ fn test_temp() {
|
|||
|
||||
#[test]
|
||||
fn test_determinism() {
|
||||
test("pascal m", "1 A tesla (spectral_irradiance_frequency)");
|
||||
test("weber / m", "1 m tesla");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue