无法获得负数的平方根 [英] Cannot get square root of negative number

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

问题描述

我当前正在尝试获取-1的平方根,但是在Java中,Math.sqrt()返回NaN表示任何负值.如何在Java中获得-1的平方根?

I am currently trying to get the square root of -1, but in java, Math.sqrt() return NaN for any negative value. How do I get the square root of -1 in Java?

推荐答案

您无法获得负数的平方根.您可以做的是使用方法执行复数运算,以创建一个复数类.您可以在此处查看示例: http://introcs.cs .princeton.edu/java/97data/Complex.java.html

You can't get the square root of a negative number. What you could do is to create a Complex number class with methods to carry out complex number arithmetic. You may have a look here for an example: http://introcs.cs.princeton.edu/java/97data/Complex.java.html

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

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