-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undue overflow or underflow on complex division #23
Comments
Yes, we use the naive algebraic formula, and it does have this downside. But the implementation of Also, the alternatives I see would fare poorly with non-float types or otherwise limited precision. For instance, with Gaussian integers like When Rust gets stable specialization, maybe we could implement a different |
I know there are more sophisticated algorithms out there, but this is pretty accurate for your examples: fn finv<T: Float>(c: Complex<T>) -> Complex<T> {
let norm = c.norm();
c.conj() / norm / norm
}
fn fdiv<T: Float>(a: Complex<T>, b: Complex<T>) -> Complex<T> {
a * finv(b)
} |
Thank you for detailed explanation. I understand the reason why the current implementation uses the naive algebraic formula. Of course, implementing specialized |
Could you add the |
@benruijl -- Have you tested whether the |
@cupiver, I did. Your snippet works for me and I would like to see it included in the library. |
These use the floating point `norm()` to avoid cases where the more generic `inv()` and `div()` might overflow in `norm_sqr()`. Closes rust-num#23.
These use the floating point `norm()` to avoid cases where the more generic `inv()` and `div()` might overflow in `norm_sqr()`. Closes rust-num#23.
Complex division
c1 / c2
might return an incorrect value whenc2.norm_sqr()
overflows or underflows.For instance,
The text was updated successfully, but these errors were encountered: