finding cube root in C++?

后端 未结 12 675
自闭症患者
自闭症患者 2020-12-03 15:18

Strange things happen when i try to find the cube root of a number.

The following code returns me undefined. In cmd : -1.#IND

cout<

        
12条回答
  •  误落风尘
    2020-12-03 15:36

    While (-1)^3 = -1, you can't simply take a rational power of a negative number and expect a real response. This is because there are other solutions to this rational exponent that are imaginary in nature.
    http://www.wolframalpha.com/input/?i=x^(1/3),+x+from+-5+to+0

    Similarily, plot x^x. For x = -1/3, this should have a solution. However, this function is deemed undefined in R for x < 0.

    Therefore, don't expect math.h to do magic that would make it inefficient, just change the signs yourself.

提交回复
热议问题