Unexpected powf behaviour

The following code:

fn main() {
    let v = (-0.23280871681335991_f64).powf(-0.0027397260273972603_f64);
    println!("{:?}", v);
    let v = -0.23280871681335991_f64.powf(-0.0027397260273972603_f64);
    println!("{:?}", v);
}

produces this output:

NaN
-1.004001238791221

I'd expect both to be equivalent,but apparently they are not. Is it expected?

https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=df37bb659b1ec9567fe4803a04959be6

let v = -0.23280871681335991_f64.powf(-0.0027397260273972603_f64);

is equivalent to

let v = -(0.23280871681335991_f64.powf(-0.0027397260273972603_f64));
1 Like

Right, but it doesn't explain the NaN.

The result of raising a negative number to a fractional power cannot be represented as a real number, so a NaN is returned; this is expected.

4 Likes

Now it makes sense.
Thank you!