Real cube root of a negative number

前端 未结 3 2017
长情又很酷
长情又很酷 2020-12-03 21:10

I\'m trying to see if there is a function to directly get the real cube root of a negative number. For example, in Java, there is the Math.cbrt() function. I\'m

3条回答
  •  既然无缘
    2020-12-03 21:50

    In Java something like this :

    There are 3 cube-roots. Assuming you want the root that is real, you should do this:
    
    x = 8;  //  Your value
    
    if (x > 0)
        System.out.println(Math.pow(x, 1.0 / 3.0));
    else
        System.out.println(-Math.pow(-x, 1.0 / 3.0));
    

提交回复
热议问题