我正在尝试求负数的立方根,但得到的是 NaN。有帮助吗?
System.out.println(Math.pow(-8, 1.0 / 3.0));
最佳答案
Math.pow
的 Java 文档指出:
If the first argument is finite and less than zero [...] [and] if the second argument is finite and not an integer, then the result is NaN.
您可以使用 Math.cbrt
获取立方根:
double result = Math.cbrt(-8.0);
关于java - 负数的立方根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290804/