Skip to content

Imprecision of complex natural logarithm for arguments close to 1 #122

Open
@Expander

Description

@Expander

I found that in version 0.4.5 for complex numbers close to 1 the implementation of the complex logarithm ln looses many digits of precision:

use num::complex::Complex;

fn main() {
    let z = Complex::new(0.999995168714454, -0.004396919500211628);
    println!("z.ln() = {}", z.ln());
    // result:    0.0000048351532916926595 - 0.0043969124079359465i
    // expected result: 4.8351532916397e-6 - 0.0043969124079359465i
}

Link to rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d300b26da9fc5bed4304f52b99989386

To my knowledge there are algorithms to avoid such problems, for example by scaling the magnitude of the complex number accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions