Skip to content

Arc-hyperbolic-trigonometric functions are very inaccurate #104548

Closed
@pavpanchekha

Description

@pavpanchekha

The functions asinh and acosh for both f32 and f64 are quite inaccurate, both for very large inputs (because x * x overflows) and, for asinh, for very small inputs (due to kinda-complex cancellation).

I tried this code:

fn main() {
    println!("{}", (600.0 as f64).sinh().asinh());
    println!("{}", (1e-16 as f64).sinh().asinh());
    println!("{}", (600.0 as f64).cosh().acosh());
    
    println!("{}", (60.0 as f32).sinh().asinh());
    println!("{}", (1e-8 as f32).sinh().asinh());
    println!("{}", (60.0 as f32).cosh().acosh());
}

This code evaluates asinh(sinh(x)) and acosh(cosh(x)). Naturally I expected the output to be x, but instead the output is inf and 0, indicating overflow and cancellation.

Meta

I ran this in the Rust Playground on both Stable (1.65.0) and Nightly (2022-11-16 e9493d63c2a57b91556d).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions