You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current complex number division implementation causes intermediate values to over/underflow leading to NaN.
use crate::num_complex::Complex;
use num_complex;
fn main() {
let a = Complex::<f32>::new(489286830000000000000.0, 0.);
let b = Complex::<f32>::new(73718980000000000000.0, 0.);
println!("{}", a / b); // prints NaN+0i, should be around 6.6+0i
}
The problem is mostly that Div is generic for all T: Num, and Rust doesn't have specialization (yet) for us to do anything better for floating point types. This was discussed in #23, and as a result #41 added simple finv() and fdiv() methods for T: Float that do get much closer.
In this playground, the real-only division gets 6.6371894, as does your smith implementation, while fdiv gets 6.63719. I would be open to your improvements in fdiv if you'd like to open a pull request.
Thank you for the answer, I checked the old issues but i didn't found #23. At the moment I can switch to fdiv().
I'm closing this issue since it is a duplicate, if I implement the Smith's method I will open a pull request.
Current complex number division implementation causes intermediate values to over/underflow leading to NaN.
Please see this papers for a better implementation:
https://www.scilab.org/tutorials/scilab-not-naive-%E2%80%93-tutorial
https://arxiv.org/abs/1210.4539
Here a link to rust playground with a comparison of the two implementations: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1b4d0ea769f0704f0902718796effce4
The text was updated successfully, but these errors were encountered: