Skip to content

f.sin().asin() sometimes returns NaN #4207

@RalfJung

Description

@RalfJung

This code prints some NaN with latest Miri (not yet synced into rustc):

fn main() {
    let f = std::f64::consts::FRAC_PI_2;
    for _ in 0..64 {
        println!("{}", (dbg!(f.sin()).asin() - std::f64::consts::FRAC_PI_2).abs());
    }
}

The reason is that f.sin() can return values slightly above 1 due to the imprecision we add, and then asin() returns NaN. That seems undesirable.

@tgross35 is there some sort of guarantee that f.sin(), while it can be imprecise, will always return values that strictly satisfy x <= 1.0? Or should asin be more accepting of values slightly above NaN?

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