Skip to content

Using Complex<BigFloat>::sqrt can give incorrect results #13

@Cryoris

Description

@Cryoris

Summary

Taking the square root of some complex numbers can give incorrect results, when using num_complex::Complex<BigFloat> as type. For example

use num_complex::Complex; // 0.4.6
use num_bigfloat::{BigFloat, ONE};  // 1.7.1

fn main() {
    let c = Complex::<BigFloat>::new(ONE, -ONE);
    println!("{}", c.sqrt().powi(2));  // prints 1+i, but should be 1-i
}

The problem seems to be that c.sqrt() has a flipped sign in the imaginary part. Running the example with f64 gives the expected 1-i result.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions