miri icon indicating copy to clipboard operation
miri copied to clipboard

atan2 NaN-result mismatch

Open Forever119 opened this issue 2 weeks ago • 3 comments

For selected NaN inputs, Miri returns a finite angle while native execution returns NaN.

Program

fn main() {
    println!("atan2f={:?}", f32::NAN.atan2(f32::NEG_INFINITY));
    println!("atan2={:?}", f64::NAN.atan2(0.0));
}

Output

native:
atan2f=NaN
atan2=NaN

miri:
atan2f=3.1415927
atan2=1.5707963267948966

Forever119 avatar Nov 19 '26 13:11 Forever119

Is there a standard somewhere saying what should happen?

RalfJung avatar Nov 19 '26 15:11 RalfJung

The C standard says nothing about NaNs. But I tend to agree that returning a non-NaN output on a NaN input is odd.

The odd thing is that we do use native arithmetic here. I am not sure what is going on that we're not ending up forwarding the native NaN...

RalfJung avatar Nov 19 '26 17:11 RalfJung

Thanks, I found the problem, it should be fixed soon. :)

RalfJung avatar Nov 19 '26 18:11 RalfJung