# F64 powf detecting undefined results

**URL:** <https://users.rust-lang.org/t/f64-powf-detecting-undefined-results/55440>\
**Category:** help\
**Created:** [February 10, 2021, 11:35pm UTC](https://users.rust-lang.org/t/f64-powf-detecting-undefined-results/55440 "2021-02-10T23:35:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bg641](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bg641](https://users.rust-lang.org/u/bg641)\
**Post date:** [February 10, 2021, 11:35pm UTC](https://users.rust-lang.org/t/f64-powf-detecting-undefined-results/55440/1 "2021-02-10T23:35:37Z")

</div>

My knowledge of mathematics says to me that if I attempt to perform (-5)^0.5, the result should be undefined, or some imaginary number (in this case ~ -2.23i). When I attempt to do this with rust:

`-5.0f64.powf(0.5f64)`

The result is `-2.23606797749979`, without anything to indicate that this is an imaginary number and would normally be undefined.

Is there an efficient way to determine whether or not `powf()` results in an imaginary number/undefined result?

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/sfackler/32/132_2.png) [@sfackler](https://users.rust-lang.org/u/sfackler)\
**Post date:** [February 10, 2021, 11:59pm UTC](https://users.rust-lang.org/t/f64-powf-detecting-undefined-results/55440/2 "2021-02-10T23:59:45Z")

</div>

The operator precedence of your code is wrong - it is calculating the square root of 5 and then negating that: `-(5.0f64.powf(0.5f64))`. If you correct that, you get a NaN as expected: [Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=aee059d40beb6929d2fc42300bb7773f)

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [May 11, 2021, 11:59pm UTC](https://users.rust-lang.org/t/f64-powf-detecting-undefined-results/55440/3 "2021-05-11T23:59:58Z")

</div>

Closed on May 11, 2021, 11:59pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
