立方根的负数 [英] Cube root of a negative number

查看:234
本文介绍了立方根的负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到负数的立方根,但我得到了一个N​​aN。有什么帮助吗?

I'm trying to find the cube root of a negative number but I get a NaN. Any help?

System.out.println(Math.pow(-8, 1.0 / 3.0));


推荐答案

Math的Java文档.pow 状态:


如果第一个参数是有限且小于零[...] [和]如果第二个参数是有限的而不是整数,则结果为NaN。

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 获取多维数据集根目录:

You could use Math.cbrt to get the cube root:

double result = Math.cbrt(-8.0);

这篇关于立方根的负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆