uom
uom copied to clipboard
Conversion to/from complex storage types is wrong
Heya, i have run into the following issue:
Lets assume a complex impedance like Z = (123 + 321j) * ohm
use uom::fmt::DisplayStyle;
use uom::si::complex64::ElectricalResistance;
use uom::si::electrical_resistance::ohm;
use uom::num_complex::Complex64;
fn main() {
let n = Complex64::new(123.0,321.0);
let unit = ElectricalResistance::new::<ohm>(n);
println!("{} -> {}", n, unit.into_format_args(ohm,DisplayStyle::Abbreviation));
assert_eq!(n,unit.get::<ohm>());
}
this fails:
123+321i -> 343.7586362551492+0i Ω
thread 'main' panicked at src\main.rs:10:5:
assertion `left == right` failed
left: Complex { re: 123.0, im: 321.0 }
right: Complex { re: 343.7586362551492, im: 0.0 }
343.7586362551492
being the norm of the number.
I have looked at the implementing PR: while i would expect the pure unit conversion factor to be a floating point type, the actual conversion operation must be in the complex numbers, otherwise the operation is one-way (there are infinite solutions to |z|^2 = re^2 + im^2
for a single given z; think vectors describing a circle of radius z).
Im gonna have a go at either understanding where im wrong in my assumptions, or fixing this, as i really want complex impedance :D