简体   繁体   English

Math.Pow C# 负数

[英]Math.Pow C# negative number

In Excel when I type in:在 Excel 中输入时:

=-4^(1/3)

It gives me它给了我在此处输入图片说明

However when I do the same thing in C# it gives me Nan.但是,当我在 C# 中做同样的事情时,它给了我 Nan。 How do I achieve the above in C#?我如何在 C# 中实现上述目标?

What Excel does is (-1)*(4^(1/3)). Excel 所做的是 (-1)*(4^(1/3))。 The NaN comes from the fact that the correct result is obviously a complex number, so you might want to look into C# complex type. NaN 来自这样一个事实,即正确的结果显然是一个复数,因此您可能需要查看 C# 复杂类型。

You can use double x =-1*(double)Math.Pow(4, (double)(1.0/3)) ;您可以使用double x =-1*(double)Math.Pow(4, (double)(1.0/3)) ; to get same results in csharp.在 csharp 中获得相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM